function Block::blockForm

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

Adds the configuration form elements specific to this views block plugin.

This method allows block instances to override the views items_per_page.

Parameters

\Drupal\views\Plugin\Block\ViewsBlock $block: The ViewsBlock plugin.

array $form: The form definition array for the block configuration form.

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

Return value

array The renderable form array representing the entire configuration form.

See also

\Drupal\views\Plugin\Block\ViewsBlock::blockForm()

File

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

Class

Block
The plugin that handles a block.

Namespace

Drupal\views\Plugin\views\display

Code

public function blockForm(ViewsBlock $block, array &$form, FormStateInterface $form_state) {
    $allow_settings = array_filter($this->getOption('allow'));
    $block_configuration = $block->getConfiguration();
    foreach ($allow_settings as $type => $enabled) {
        if (empty($enabled)) {
            continue;
        }
        switch ($type) {
            case 'items_per_page':
                $form['override']['items_per_page'] = [
                    '#type' => 'select',
                    '#title' => $this->t('Items per block'),
                    '#options' => [
                        'none' => $this->t('@count (default setting)', [
                            '@count' => $this->getPlugin('pager')
                                ->getItemsPerPage(),
                        ]),
                        1 => 1,
                        2 => 2,
                        3 => 3,
                        4 => 4,
                        5 => 5,
                        6 => 6,
                        10 => 10,
                        12 => 12,
                        20 => 20,
                        24 => 24,
                        40 => 40,
                        48 => 48,
                    ],
                    '#default_value' => $block_configuration['items_per_page'],
                ];
                break;
        }
    }
    return $form;
}

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