You are here

FeedImporterAddForm.php in Feed Import 8

File

src/Form/FeedImporterAddForm.php
View source
<?php

namespace Drupal\feed_import\Form;

use Drupal\feed_import\Form\FeedImporterFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\feed_import_base\FeedImport;

/**
 * Form for adding a feed importer.
 */
class FeedImporterAddForm extends FeedImporterFormBase {

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form['entity'] = [
      '#type' => 'select',
      '#options' => FeedImport::getAllEntities(),
      '#default_value' => 'node',
      '#title' => $this
        ->t('Entity name'),
      '#description' => $this
        ->t('Entity where you want to import content. Ex: node, user, ...'),
      '#maxlength' => 64,
      '#required' => TRUE,
    ];
    $form['cron_import'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Import at cron'),
      '#default_value' => FALSE,
      '#description' => $this
        ->t('Check this if you want to import feed items when cron runs.'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    drupal_set_message($this
      ->t('Feed Importer %name was created.', array(
      '%name' => $this->entity
        ->label(),
    )));
  }

  /**
   * {@inheritdoc}
   */
  public function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form, $form_state);
    $actions['submit']['#value'] = $this
      ->t('Create new feed importer');
    return $actions;
  }

}

Classes

Namesort descending Description
FeedImporterAddForm Form for adding a feed importer.