You are here

public function FieldsForm::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/FieldsForm.php, line 189
Contains \Drupal\feed_import\Form\FieldsForm

Class

FieldsForm

Namespace

Drupal\feed_import\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $v = $form_state
    ->getValues();
  if (!$this->feed) {
    return;
  }
  $e = FeedImport::getEntityInfo($this->feed->entity);
  $fields = array();
  for ($i = 0; $i <= $form_state
    ->get('current_item'); $i++) {
    if (empty($v['fields']['container_' . $i]['field'])) {
      continue;
    }
    $f =& $v['fields']['container_' . $i];
    $fields[$f['field']] = array(
      'field' => $f['field'],
      'column' => isset($e->fields[$f['field']]),
      'paths' => array_filter(preg_split('/\\r?\\n/', $f['paths']), 'strlen'),
      'default_action' => (int) $f['default_action'],
      'default_value' => $f['default_value'],
      'update_mode' => (int) $f['update_mode'],
      'filters' => isset($this->feed->settings['fields'][$f['field']]['filters']) ? $this->feed->settings['fields'][$f['field']]['filters'] : array(),
      'prefilters' => isset($this->feed->settings['fields'][$f['field']]['prefilters']) ? $this->feed->settings['fields'][$f['field']]['prefilters'] : array(),
    );
    unset($f);
  }
  $this->feed->settings['uniq_path'] = $v['uniq'];
  $this->feed->settings['fields'] = $fields;

  // Save feed.
  if (FeedImport::saveFeed($this->feed)) {
    drupal_set_message(t('Feed saved'));
  }
}