You are here

public function EditFeedForm::buildForm in Feed Import 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/EditFeedForm.php, line 31

Class

EditFeedForm
Feed Importer edit form.

Namespace

Drupal\feed_import\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $feed_importer = NULL) {
  $this->feed = FeedImport::loadFeed($fid);
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Feed name'),
    '#maxlength' => 64,
    '#description' => t('This usually is source name.'),
    '#default_value' => $this->feed ? $this->feed->name : NULL,
    '#required' => TRUE,
  );
  $form['entity'] = array(
    '#type' => 'select',
    '#options' => FeedImport::getAllEntities(),
    '#default_value' => $this->feed->entity,
    '#title' => t('Entity name'),
    '#description' => t('Entity where you want to import content. Ex: node, user, ...'),
    '#maxlength' => 64,
    '#required' => TRUE,
    '#disabled' => !empty($this->feed->settings['fields']),
  );
  $form['cron_import'] = array(
    '#type' => 'checkbox',
    '#title' => t('Import at cron'),
    '#default_value' => $this->feed->cron_import,
    '#description' => t('Check this if you want to import feed items when cron runs.'),
  );
  $form['feed'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Delete protection'),
    '#description' => t('Reschedule items if one of the below conditions is met.') . ' ' . t('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' => $this->feed->settings['feed']['protect_on_invalid_source'],
  );
  $form['feed']['protect_on_fewer_items'] = array(
    '#type' => 'textfield',
    '#title' => t('Total number of items is less than'),
    '#default_value' => $this->feed->settings['feed']['protect_on_fewer_items'],
    '#description' => t('You can also use a percentage by appending %. Percentage is reported to items count of last import.') . ' ' . t('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' => isset($this->feed->settings['preprocess']) ? $this->feed->settings['preprocess'] : '',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save feed'),
  );
  return $form;
}