function SettingsForm::buildForm

Same name in this branch
  1. 9 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
Same name in other branches
  1. 8.9.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  2. 8.9.x core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::buildForm()
  3. 10 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  4. 11.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  5. 11.x core/modules/navigation/src/Form/SettingsForm.php \Drupal\navigation\Form\SettingsForm::buildForm()
  6. 10 core/modules/navigation/src/Form/SettingsForm.php \Drupal\navigation\Form\SettingsForm::buildForm()

Overrides ConfigFormBase::buildForm

File

core/modules/aggregator/src/Form/SettingsForm.php, line 106

Class

SettingsForm
Configures aggregator settings for this site.

Namespace

Drupal\aggregator\Form

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.