public function SettingsForm::buildForm in Drupal 9
Same name in this branch
- 9 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
- 9 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::buildForm()
Same name and namespace in other branches
- 8 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::buildForm()
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 ConfigFormBase::buildForm
File
- core/
modules/ aggregator/ src/ Form/ SettingsForm.php, line 106
Class
- SettingsForm
- Configures aggregator settings for this site.
Namespace
Drupal\aggregator\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('aggregator.settings');
// Global aggregator settings.
$form['aggregator_allowed_html_tags'] = [
'#type' => 'textfield',
'#title' => $this
->t('Allowed HTML tags'),
'#size' => 80,
'#maxlength' => 255,
'#default_value' => $config
->get('items.allowed_html'),
'#description' => $this
->t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),
];
// Only show basic configuration if there are actually options.
$basic_conf = [];
if (count($this->definitions['fetcher']) > 1) {
$basic_conf['aggregator_fetcher'] = [
'#type' => 'radios',
'#title' => $this
->t('Fetcher'),
'#description' => $this
->t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'),
'#options' => $this->definitions['fetcher'],
'#default_value' => $config
->get('fetcher'),
];
}
if (count($this->definitions['parser']) > 1) {
$basic_conf['aggregator_parser'] = [
'#type' => 'radios',
'#title' => $this
->t('Parser'),
'#description' => $this
->t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'),
'#options' => $this->definitions['parser'],
'#default_value' => $config
->get('parser'),
];
}
if (count($this->definitions['processor']) > 1) {
$basic_conf['aggregator_processors'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Processors'),
'#description' => $this
->t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'),
'#options' => $this->definitions['processor'],
'#default_value' => $config
->get('processors'),
];
}
if (count($basic_conf)) {
$form['basic_conf'] = [
'#type' => 'details',
'#title' => $this
->t('Basic configuration'),
'#description' => $this
->t('For most aggregation tasks, the default settings are fine.'),
'#open' => TRUE,
];
$form['basic_conf'] += $basic_conf;
}
// Call buildConfigurationForm() on the active fetcher and parser.
foreach ([
'fetcher',
'parser',
] as $type) {
$active = $config
->get($type);
if (array_key_exists($active, $this->definitions[$type])) {
$instance = $this->managers[$type]
->createInstance($active);
if ($instance instanceof PluginFormInterface) {
$form = $instance
->buildConfigurationForm($form, $form_state);
// Store the instance for validate and submit handlers.
// Keying by ID would bring conflicts, because two instances of a
// different type could have the same ID.
$this->configurableInstances[] = $instance;
}
}
}
// Implementing processor plugins will expect an array at $form['processors'].
$form['processors'] = [];
// Call buildConfigurationForm() for each active processor.
foreach ($this->definitions['processor'] as $id => $definition) {
if (in_array($id, $config
->get('processors'))) {
$instance = $this->managers['processor']
->createInstance($id);
if ($instance instanceof PluginFormInterface) {
$form = $instance
->buildConfigurationForm($form, $form_state);
// Store the instance for validate and submit handlers.
// Keying by ID would bring conflicts, because two instances of a
// different type could have the same ID.
$this->configurableInstances[] = $instance;
}
}
}
return parent::buildForm($form, $form_state);
}