From f1c8285a670082a2149069c39bb527cffa87fc17 Mon Sep 17 00:00:00 2001 From: GeorgeUU Date: Tue, 4 Jul 2017 17:30:35 +0100 Subject: [PATCH] Set category fieldmap based on selected group With multiple category field layouts, there can be a mismatch between the expected fields and the fields set in the map. The current code appears to always grab the first fieldLayout from the db. This fix explicitly takes the selected groups fieldLayout to populate the fieldmap. --- services/Export_CategoryService.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/Export_CategoryService.php b/services/Export_CategoryService.php index 57cc23a..92b3bea 100644 --- a/services/Export_CategoryService.php +++ b/services/Export_CategoryService.php @@ -68,10 +68,13 @@ public function getFields(array $settings, $reset) ); // Set the dynamic fields for this type - foreach (craft()->fields->getLayoutByType(ElementType::Category)->getFields() as $field) { - $data = $field->getField(); - $fields[$data->handle] = array('name' => $data->name, 'checked' => 1, 'fieldtype' => $data->type); + if( $group = craft()->categories->getGroupById( $settings["elementvars"]["group"] ) ){ + foreach (craft()->fields->getLayoutById( $group->fieldLayoutId )->getFields() as $field) { + $data = $field->getField(); + $fields[$data->handle] = array('name' => $data->name, 'checked' => 1, 'fieldtype' => $data->type); + } } + } else { // Get the stored map