You are here

public function FeedImporterEditForm::form in Feed Import 8

Gets the actual form array to be built.

Overrides FeedImporterFormBase::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/FeedImporterEditForm.php, line 17

Class

FeedImporterEditForm
Form for adding a feed importer.

Namespace

Drupal\feed_import\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $feed_importer = $this->entity;
  $form['entity'] = array(
    '#type' => 'select',
    '#options' => FeedImport::getAllEntities(),
    '#default_value' => $feed_importer
      ->getEntity(),
    '#title' => t('Entity name'),
    '#description' => t('Entity where you want to import content. Ex: node, user, ...'),
    '#maxlength' => 64,
    '#required' => TRUE,
    '#disabled' => !empty($settings['fields']),
  );
  $form['cron_import'] = array(
    '#type' => 'checkbox',
    '#title' => t('Import at cron'),
    '#default_value' => $feed_importer
      ->getCronImport(),
    '#description' => t('Check this if you want to import feed items when cron runs.'),
  );
  $form['feed'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
    '#title' => t('Delete protection'),
    '#description' => t('Reschedule items if one of the below conditions is met. This is useful for cron imported items.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['feed']['protect_on_invalid_source'] = array(
    '#type' => 'checkbox',
    '#title' => t('Source file or network is unavailable'),
    '#default_value' => $feed_importer
      ->getProtectInvalidSource(),
  );
  $form['feed']['protect_on_fewer_items'] = array(
    '#type' => 'textfield',
    '#title' => t('Total number of items is less than'),
    '#default_value' => $feed_importer
      ->getProtectFewerItems(),
    '#description' => t('You can also use a percentage by appending %. Percentage is reported to items count of last import. Use 0 to ignore this setting.'),
  );
  $form['preprocess'] = array(
    '#type' => 'textfield',
    '#title' => t('Pre-process callback'),
    '#description' => t('You can use a pre-process function before the feed is imported in order to make some changes to configuration.'),
    '#default_value' => $feed_importer
      ->getPreprocess(),
  );
  return $form;
}