You are here

public function ParserBase::mappingFormSubmit in Feeds extensible parsers 8

Submit handler for the mapping form.

Parameters

array $form: The mapping form definition.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the mapping form.

Overrides ParserBase::mappingFormSubmit

File

src/Feeds/Parser/ParserBase.php, line 552

Class

ParserBase
The Feeds extensible parser.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

public function mappingFormSubmit(array &$form, FormStateInterface $form_state) {
  $config = [];

  // Set context.
  $config['context'] = [
    'value' => $form_state
      ->getValue('context'),
  ];

  // Set sources.
  // @todo refactor to let parsers use custom sources directly.
  $config['sources'] = [];
  $mappings = $form_state
    ->getValue('mappings');
  foreach ($mappings as $i => $mapping) {
    foreach ($mapping['map'] as $subtarget => $map) {
      if (empty($map['select'])) {
        continue;
      }
      if ($map['select'] == '__new') {
        $name = $map['__new']['machine_name'];
      }
      else {
        $name = $map['select'];
      }
      $source = $this->feedType
        ->getCustomSource($name);
      if ($source) {
        unset($source['machine_name']);
        $config['sources'][$name] = $source;
      }
    }
  }
  $this
    ->setConfiguration($config);
}