Loading gathercontent_ui/src/Form/MappingEditForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ class MappingEditForm extends MappingEditFormBase { // We need to modify field for checkboxes and field instance for radios. foreach ($template['related']->structure->groups as $group) { foreach ($group->fields as $gcField) { foreach ($this->flattenGroup($group->fields) as $gcField) { $local_field_id = $this->mappingData[$group->id]['elements'][$gcField->id]; if ($gcField->type === 'choice_checkbox') { if (!empty($local_field_id)) { Loading gathercontent_ui/src/Form/MappingEditFormBase.php +3 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\gathercontent_ui\Form; use Drupal\gathercontent_ui\Traits\MappingTrait; use GatherContent\DataTypes\Template; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; Loading @@ -22,6 +23,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class MappingEditFormBase extends EntityForm implements ContainerInjectionInterface { use MappingTrait; /** * Flag for mapping if it's new. * Loading gathercontent_ui/src/Form/MappingEditSteps/MappingStepEdit.php +2 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,8 @@ class MappingStepEdit extends MappingSteps { ]; } foreach ($group->fields as $gc_field) { $flat_fields = $this->flattenGroup($group->fields); foreach ($flat_fields as $gc_field) { $d_fields = []; if (isset($formState->getTriggeringElement()['#name'])) { // We need different handling for changed group. Loading gathercontent_ui/src/Form/MappingEditSteps/MappingStepNew.php +7 −2 Original line number Diff line number Diff line Loading @@ -128,7 +128,8 @@ class MappingStepNew extends MappingSteps { ]; } foreach ($group->fields as $gc_field) { $flat_fields = $this->flattenGroup($group->fields); foreach ($flat_fields as $gc_field) { $d_fields = []; if ($formState->getTriggeringElement()['#name'] !== 'content_type') { // We need different handling for changed fieldset. Loading @@ -152,12 +153,16 @@ class MappingStepNew extends MappingSteps { else { $d_fields = $this->filterFields($gc_field, $contentType, $entityType); } $default_value = NULL; if ($formState->hasValue($group->id) && $formState->getValue($group->id)['elements'][$gc_field->id]) { $default_value = $formState->getValue($group->id)['elements'][$gc_field->id]; } $form['mapping'][$group->id]['elements'][$gc_field->id] = [ '#type' => 'select', '#options' => $d_fields, '#title' => (!empty($gc_field->label) ? $gc_field->label : $gc_field->title), '#empty_option' => $this->t("Don't map"), '#default_value' => $formState->hasValue($group->id)['elements'][$gc_field->id] ? $formState->getValue($group->id)['elements'][$gc_field->id] : NULL, '#default_value' => $default_value, '#attributes' => [ 'class' => [ 'gathercontent-ct-element', Loading gathercontent_ui/src/Form/MappingEditSteps/MappingSteps.php +37 −29 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\gathercontent_ui\Form\MappingEditSteps; use Drupal\gathercontent_ui\Traits\MappingTrait; use GatherContent\DataTypes\Element; use GatherContent\DataTypes\ElementText; use Drupal\Core\DependencyInjection\DependencySerializationTrait; Loading @@ -21,6 +22,7 @@ abstract class MappingSteps { use StringTranslationTrait; use DependencySerializationTrait; use MappingTrait; /** * Mapping object. Loading Loading @@ -231,37 +233,18 @@ abstract class MappingSteps { continue; } $lang_code = 'und'; if ($translatable) { if ( ($groupType == 'content' && in_array($this->template['related']->structure->groups[$groupId]->fields[$k]->type, ['text', 'guidelines']) ) || !in_array($element, ${$groupType . '_fields'}[$group['language']]) ) { ${$groupType . '_fields'}[$group['language']][] = $element; } else { if (!strpos($element, '||')) { $formState->setErrorByName($groupId, $this->t('A GatherContent field can only be mapped to a single Drupal field. So each field can only be mapped to once.')); } $lang_code = $group['language']; } } else { if ( ($groupType == 'content' && in_array($this->template['related']->structure->groups[$groupId]->fields[$k]->type, ['text', 'guidelines']) ) || !in_array($element, ${$groupType . '_fields'}) ) { ${$groupType . '_fields'}[] = $element; } else { if (!strpos($element, '||')) { if (isset(${$groupType . '_fields'}[$lang_code]) && in_array($element, ${$groupType . '_fields'}[$lang_code])) { $formState->setErrorByName($groupId, $this->t('A GatherContent field can only be mapped to a single Drupal field. So each field can only be mapped to once.')); continue; } } if ($groupType == 'content' && in_array($this->getFieldFromId($k, $groupId)->type, ['text', 'guidelines'])) { ${$groupType . '_fields'}[$lang_code][] = $element; } } } Loading Loading @@ -294,6 +277,31 @@ abstract class MappingSteps { } } /** * Wrapper function for filterFieldsRecursively. * * Use for filtering only equivalent fields. * * @param string $id * GatherContent id of the field to retrieve. * @param string $group_id * GatherContent id of the group containing the field. * * @return \GatherContent\DataTypes\Element * The GatherContent field.. */ protected function getFieldFromId($id, $group_id) { if ($group_id && !strpos($id, '/')) { return $this->template['related']->structure->groups[$group_id]->fields[$id]; } if ($group_id && strpos($id, '/')) { $ids = explode('/', $id); $component = $this->template['related']->structure->groups[$group_id]->fields[$ids[0]]; $children = $component->getChildrenFields(); return $children[$ids[1]]; } } /** * Wrapper function for filterFieldsRecursively. * Loading Loading
gathercontent_ui/src/Form/MappingEditForm.php +1 −1 Original line number Diff line number Diff line Loading @@ -200,7 +200,7 @@ class MappingEditForm extends MappingEditFormBase { // We need to modify field for checkboxes and field instance for radios. foreach ($template['related']->structure->groups as $group) { foreach ($group->fields as $gcField) { foreach ($this->flattenGroup($group->fields) as $gcField) { $local_field_id = $this->mappingData[$group->id]['elements'][$gcField->id]; if ($gcField->type === 'choice_checkbox') { if (!empty($local_field_id)) { Loading
gathercontent_ui/src/Form/MappingEditFormBase.php +3 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\gathercontent_ui\Form; use Drupal\gathercontent_ui\Traits\MappingTrait; use GatherContent\DataTypes\Template; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityFieldManagerInterface; Loading @@ -22,6 +23,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class MappingEditFormBase extends EntityForm implements ContainerInjectionInterface { use MappingTrait; /** * Flag for mapping if it's new. * Loading
gathercontent_ui/src/Form/MappingEditSteps/MappingStepEdit.php +2 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,8 @@ class MappingStepEdit extends MappingSteps { ]; } foreach ($group->fields as $gc_field) { $flat_fields = $this->flattenGroup($group->fields); foreach ($flat_fields as $gc_field) { $d_fields = []; if (isset($formState->getTriggeringElement()['#name'])) { // We need different handling for changed group. Loading
gathercontent_ui/src/Form/MappingEditSteps/MappingStepNew.php +7 −2 Original line number Diff line number Diff line Loading @@ -128,7 +128,8 @@ class MappingStepNew extends MappingSteps { ]; } foreach ($group->fields as $gc_field) { $flat_fields = $this->flattenGroup($group->fields); foreach ($flat_fields as $gc_field) { $d_fields = []; if ($formState->getTriggeringElement()['#name'] !== 'content_type') { // We need different handling for changed fieldset. Loading @@ -152,12 +153,16 @@ class MappingStepNew extends MappingSteps { else { $d_fields = $this->filterFields($gc_field, $contentType, $entityType); } $default_value = NULL; if ($formState->hasValue($group->id) && $formState->getValue($group->id)['elements'][$gc_field->id]) { $default_value = $formState->getValue($group->id)['elements'][$gc_field->id]; } $form['mapping'][$group->id]['elements'][$gc_field->id] = [ '#type' => 'select', '#options' => $d_fields, '#title' => (!empty($gc_field->label) ? $gc_field->label : $gc_field->title), '#empty_option' => $this->t("Don't map"), '#default_value' => $formState->hasValue($group->id)['elements'][$gc_field->id] ? $formState->getValue($group->id)['elements'][$gc_field->id] : NULL, '#default_value' => $default_value, '#attributes' => [ 'class' => [ 'gathercontent-ct-element', Loading
gathercontent_ui/src/Form/MappingEditSteps/MappingSteps.php +37 −29 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\gathercontent_ui\Form\MappingEditSteps; use Drupal\gathercontent_ui\Traits\MappingTrait; use GatherContent\DataTypes\Element; use GatherContent\DataTypes\ElementText; use Drupal\Core\DependencyInjection\DependencySerializationTrait; Loading @@ -21,6 +22,7 @@ abstract class MappingSteps { use StringTranslationTrait; use DependencySerializationTrait; use MappingTrait; /** * Mapping object. Loading Loading @@ -231,37 +233,18 @@ abstract class MappingSteps { continue; } $lang_code = 'und'; if ($translatable) { if ( ($groupType == 'content' && in_array($this->template['related']->structure->groups[$groupId]->fields[$k]->type, ['text', 'guidelines']) ) || !in_array($element, ${$groupType . '_fields'}[$group['language']]) ) { ${$groupType . '_fields'}[$group['language']][] = $element; } else { if (!strpos($element, '||')) { $formState->setErrorByName($groupId, $this->t('A GatherContent field can only be mapped to a single Drupal field. So each field can only be mapped to once.')); } $lang_code = $group['language']; } } else { if ( ($groupType == 'content' && in_array($this->template['related']->structure->groups[$groupId]->fields[$k]->type, ['text', 'guidelines']) ) || !in_array($element, ${$groupType . '_fields'}) ) { ${$groupType . '_fields'}[] = $element; } else { if (!strpos($element, '||')) { if (isset(${$groupType . '_fields'}[$lang_code]) && in_array($element, ${$groupType . '_fields'}[$lang_code])) { $formState->setErrorByName($groupId, $this->t('A GatherContent field can only be mapped to a single Drupal field. So each field can only be mapped to once.')); continue; } } if ($groupType == 'content' && in_array($this->getFieldFromId($k, $groupId)->type, ['text', 'guidelines'])) { ${$groupType . '_fields'}[$lang_code][] = $element; } } } Loading Loading @@ -294,6 +277,31 @@ abstract class MappingSteps { } } /** * Wrapper function for filterFieldsRecursively. * * Use for filtering only equivalent fields. * * @param string $id * GatherContent id of the field to retrieve. * @param string $group_id * GatherContent id of the group containing the field. * * @return \GatherContent\DataTypes\Element * The GatherContent field.. */ protected function getFieldFromId($id, $group_id) { if ($group_id && !strpos($id, '/')) { return $this->template['related']->structure->groups[$group_id]->fields[$id]; } if ($group_id && strpos($id, '/')) { $ids = explode('/', $id); $component = $this->template['related']->structure->groups[$group_id]->fields[$ids[0]]; $children = $component->getChildrenFields(); return $children[$ids[1]]; } } /** * Wrapper function for filterFieldsRecursively. * Loading