You are here

public function FeedImporterAddForm::submitForm in Feed Import 8

Same name in this branch
  1. 8 src/Form/FeedImporterAddForm.old.php \Drupal\feed_import\Form\FeedImporterAddForm::submitForm()
  2. 8 src/Form/FeedImporterAddForm.php \Drupal\feed_import\Form\FeedImporterAddForm::submitForm()

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

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 EntityForm::submitForm

File

src/Form/FeedImporterAddForm.old.php, line 106

Class

FeedImporterAddForm
Form for adding a feed importer.

Namespace

Drupal\feed_import\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $v = $form_state
    ->getValues();
  $feed = (object) FeedImport::getEmptyFeed();
  $feed->machine_name = $v['machine_name'];
  $feed->settings['hashes']['options']['group'] = $v['machine_name'];
  $feed->name = $v['name'];
  $feed->entity = $v['entity'];
  $feed->cron_import = $v['cron_import'];
  if (FeedImport::saveFeed($feed)) {
    drupal_set_message(t('Feed saved'));
    $form_state
      ->setRedirect('feed_import.admin_edit', [
      'fid' => $feed->machine_name,
    ]);
  }
  else {
    drupal_set_message(t('Error saving feed'), 'error');
  }
}