You are here

public function ParserBase::mappingFormValidate in Feeds extensible parsers 8

Validate 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::mappingFormValidate

File

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

Class

ParserBase
The Feeds extensible parser.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

public function mappingFormValidate(array &$form, FormStateInterface $form_state) {
  try {

    // Validate context.
    if ($this
      ->hasConfigurableContext()) {
      if ($message = $this
        ->validateExpression($form_state
        ->getValue('context'))) {
        $message = new FormattableMarkup(Xss::filter($message, static::$htmlTags), []);
        $form_state
          ->setErrorByName('context', $message);
      }
    }

    // Validate new sources.
    $mappings = $form_state
      ->getValue('mappings');
    foreach ($mappings as $i => $mapping) {
      foreach ($mapping['map'] as $subtarget => $map) {
        if ($map['select'] == '__new' && isset($map['__new']['value'])) {
          if ($message = $this
            ->validateExpression($map['__new']['value'])) {
            $message = new FormattableMarkup(Xss::filter($message, static::$htmlTags), []);
            $form_state
              ->setErrorByName("mappings][{$i}][map][{$subtarget}][__new][value", $message);
          }
        }
      }
    }
  } catch (Exception $e) {

    // Exceptions due to missing libraries could occur, so catch these.
    $form_state
      ->setError($form, $e
      ->getMessage());
  }
}