Esempio n. 1
0
 /**
  * Processes the form state, populating the mappings on the feed type.
  */
 protected function processFormState(array $form, FormStateInterface $form_state)
 {
     // Process any plugin configuration.
     $triggering_element = $form_state->getTriggeringElement() + ['#op' => ''];
     if ($triggering_element['#op'] === 'update') {
         $this->feedType->getTargetPlugin($triggering_element['#delta'])->submitConfigurationForm($form, $form_state);
     }
     $mappings = $this->feedType->getMappings();
     foreach (array_filter((array) $form_state->getValue('mappings', [])) as $delta => $mapping) {
         $mappings[$delta]['map'] = $mapping['map'];
         if (isset($mapping['unique'])) {
             $mappings[$delta]['unique'] = array_filter($mapping['unique']);
         }
     }
     $this->feedType->setMappings($mappings);
     // Remove any mappings.
     foreach (array_keys(array_filter($form_state->getValue('remove_mappings', []))) as $delta) {
         $this->feedType->removeMapping($delta);
     }
     // Add any targets.
     if ($new_target = $form_state->getValue('add_target')) {
         $map = array_fill_keys($this->targets[$new_target]->getProperties(), '');
         $this->feedType->addMapping(['target' => $new_target, 'map' => $map]);
     }
     // Allow the #default_value of 'add_target' to be reset.
     $input =& $form_state->getUserInput();
     unset($input['add_target']);
 }