function Block::buildOptionsForm

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block::buildOptionsForm()
  2. 8.9.x core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block::buildOptionsForm()
  3. 10 core/modules/views/src/Plugin/views/display/Block.php \Drupal\views\Plugin\views\display\Block::buildOptionsForm()

Provide the default form for setting options.

Overrides DisplayPluginBase::buildOptionsForm

File

core/modules/views/src/Plugin/views/display/Block.php, line 193

Class

Block
The plugin that handles a block.

Namespace

Drupal\views\Plugin\views\display

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    switch ($form_state->get('section')) {
        case 'block_description':
            $form['#title'] .= $this->t('Block admin description');
            $form['block_description'] = [
                '#type' => 'textfield',
                '#description' => $this->t('This will appear as the name of this block in administer >> structure >> blocks.'),
                '#default_value' => $this->getOption('block_description'),
            ];
            break;
        case 'block_category':
            $form['#title'] .= $this->t('Block category');
            $form['block_category'] = [
                '#type' => 'textfield',
                '#autocomplete_route_name' => 'block.category_autocomplete',
                '#description' => $this->t('The category this block will appear under on the <a href=":href">blocks placement page</a>.', [
                    ':href' => Url::fromRoute('block.admin_display')->toString(),
                ]),
                '#default_value' => $this->getOption('block_category'),
            ];
            break;
        case 'block_hide_empty':
            $form['#title'] .= $this->t('Block empty settings');
            $form['block_hide_empty'] = [
                '#title' => $this->t('Hide block if no result/empty text'),
                '#type' => 'checkbox',
                '#description' => $this->t('Hide the block if there is no result and no empty text and no header/footer which is shown on empty result'),
                '#default_value' => $this->getOption('block_hide_empty'),
            ];
            break;
        case 'exposed_form_options':
            $this->view
                ->initHandlers();
            if (!$this->usesExposed() && parent::usesExposed()) {
                $form['exposed_form_options']['warning'] = [
                    '#weight' => -10,
                    '#markup' => '<div class="messages messages--warning">' . $this->t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>',
                ];
            }
            break;
        case 'allow':
            $form['#title'] .= $this->t('Allow settings in the block configuration');
            $options = [
                'items_per_page' => $this->t('Items per page'),
            ];
            $allow = array_keys(array_filter($this->getOption('allow')));
            $form['allow'] = [
                '#type' => 'checkboxes',
                '#default_value' => $allow,
                '#options' => $options,
            ];
            break;
    }
}

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