You are here

public function FilterForm::submitForm in Feed Import 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

src/Form/FilterForm.php, line 157
Contains \Drupal\feed_import\Form\FilterForm

Class

FilterForm

Namespace

Drupal\feed_import\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  if (!$this->feed) {
    return;
  }
  foreach ($this->feed->settings['fields'] as $field => &$item) {
    $item[$this->setting] = array();
    if (!empty($values['table_content'][$field])) {
      usort($values['table_content'][$field], array(
        'Drupal\\Component\\Utility\\SortArray',
        'sortByWeightElement',
      ));
      foreach ($values['table_content'][$field] as &$filter) {
        if (!$filter['name'] || !$filter['function']) {
          continue;
        }
        if (!$filter['params']) {
          $filter['params'] = array();
        }
        else {
          $filter['params'] = preg_split('/\\r?\\n/', $filter['params']);
        }
        $item[$this->setting][$filter['name']] = array(
          'function' => trim($filter['function']),
          'params' => $filter['params'],
        );
        $filter = NULL;
      }
    }
  }

  // Save feed.
  if (FeedImport::saveFeed($this->feed)) {
    $vars = array(
      '@filter' => $this->setting == 'filters' ? t('Filters') : t('Pre-filters'),
      '@name' => $this->feed->name,
    );
    drupal_set_message(t('@filter saved for @name', $vars));
  }
}