You are here

public function ParserBase::configFormValidate in Feeds extensible parsers 8

2 calls to ParserBase::configFormValidate()
ParserBase::sourceFormValidate in src/Feeds/Parser/ParserBase.php
XmlParser::configFormValidate in src/Feeds/Parser/XmlParser.php
1 method overrides ParserBase::configFormValidate()
XmlParser::configFormValidate in src/Feeds/Parser/XmlParser.php

File

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

Class

ParserBase
The Feeds extensible parser.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

public function configFormValidate(&$values) {

  // Throwing an exception during validation shows a nasty error to users.
  try {
    $this
      ->loadLibrary();
  } catch (RuntimeException $e) {
    $this
      ->getMessenger()
      ->addMessage($e
      ->getMessage(), 'error', FALSE);
    return;
  }

  // @todo We should do this in Feeds automatically.
  $values += $this
    ->defaultConfiguration();

  // Remove sources.
  foreach ($values['sources'] as $machine_name => $source) {
    if (!empty($source['remove'])) {
      unset($values['sources'][$machine_name]);
    }
  }

  // Add new source.
  if (strlen($values['add']['machine_name']) && strlen($values['add']['name'])) {
    if ($message = $this
      ->validateExpression($values['add']['value'])) {
      form_set_error('add][value', $message);
    }
    else {
      $values['sources'][$values['add']['machine_name']] = $values['add'];
    }
  }

  // Rebuild sources to keep the configuration values clean.
  $columns = $this
    ->getFormHeader();
  unset($columns['remove'], $columns['machine_name']);
  $columns = array_keys($columns);
  foreach ($values['sources'] as $machine_name => $source) {
    $new_value = [];
    foreach ($columns as $column) {
      $new_value[$column] = $source[$column];
    }
    $values['sources'][$machine_name] = $new_value;
  }

  // Sort by weight.
  uasort($values['sources'], 'ctools_plugin_sort');

  // Let the encoder do its thing.
  $this
    ->getEncoder()
    ->configFormValidate($values);
}