public function FeedImporterAddForm::form in Feed Import 8
Same name in this branch
- 8 src/Form/FeedImporterAddForm.old.php \Drupal\feed_import\Form\FeedImporterAddForm::form()
- 8 src/Form/FeedImporterAddForm.php \Drupal\feed_import\Form\FeedImporterAddForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ FeedImporterAddForm.old.php, line 17
Class
- FeedImporterAddForm
- Form for adding a feed importer.
Namespace
Drupal\feed_import\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$feed_importer = $this->entity;
if ($this->operation === 'edit') {
$form['#title'] = $this
->t('Edit Feed Importer: @name', [
'@name' => $feed_importer->name,
]);
}
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Feed Importer Name'),
'#maxlength' => 255,
'#description' => $this
->t('This usually is source name.'),
'#default_value' => $feed_importer->name,
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#default_value' => $feed_importer->id,
'#disabled' => !$feed_importer
->isNew(),
'#machine_name' => [
'source' => [
'label',
],
'exists' => '\\Drupal\\feed_import_base\\FeedImport::loadFeed',
],
];
$settings = $feed_importer
->getSettings();
$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,
'#disabled' => !empty($settings['fields']),
];
$form['cron_import'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Import at cron'),
'#default_value' => $feed_importer
->getCron(),
'#description' => $this
->t('Check this if you want to import feed items when cron runs.'),
];
if ($this->operation === 'edit') {
$form['feed'] = [
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => $this
->t('Delete protection'),
'#description' => $this
->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' => $this
->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' => $this
->t('Total number of items is less than'),
'#default_value' => $this->feed->settings['feed']['protect_on_fewer_items'],
'#description' => $this
->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' => $this
->t('Pre-process callback'),
'#description' => $this
->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
->getPreprocessor(),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Save feed'),
);
return $form;
}