You are here

public function BlockPluginTrait::buildConfigurationForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::buildConfigurationForm()

Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.

See also

\Drupal\Core\Block\BlockBase::blockForm()

2 calls to BlockPluginTrait::buildConfigurationForm()
InlineBlock::buildConfigurationForm in core/modules/layout_builder/src/Plugin/Block/InlineBlock.php
Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.
ViewsBlockBase::buildConfigurationForm in core/modules/views/src/Plugin/Block/ViewsBlockBase.php
Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.
2 methods override BlockPluginTrait::buildConfigurationForm()
InlineBlock::buildConfigurationForm in core/modules/layout_builder/src/Plugin/Block/InlineBlock.php
Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.
ViewsBlockBase::buildConfigurationForm in core/modules/views/src/Plugin/Block/ViewsBlockBase.php
Creates a generic configuration form for all block types. Individual block plugins can add elements to this form by overriding BlockBase::blockForm(). Most block plugins should not override this method unless they need to alter the generic form elements.

File

core/lib/Drupal/Core/Block/BlockPluginTrait.php, line 154

Class

BlockPluginTrait
Provides the base implementation of a block plugin.

Namespace

Drupal\Core\Block

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $definition = $this
    ->getPluginDefinition();
  $form['provider'] = [
    '#type' => 'value',
    '#value' => $definition['provider'],
  ];
  $form['admin_label'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Block description'),
    '#plain_text' => $definition['admin_label'],
  ];
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#maxlength' => 255,
    '#default_value' => $this
      ->label(),
    '#required' => TRUE,
  ];
  $form['label_display'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display title'),
    '#default_value' => $this->configuration['label_display'] === BlockPluginInterface::BLOCK_LABEL_VISIBLE,
    '#return_value' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
  ];

  // Add context mapping UI form elements.
  $contexts = $form_state
    ->getTemporaryValue('gathered_contexts') ?: [];
  $form['context_mapping'] = $this
    ->addContextAssignmentElement($this, $contexts);

  // Add plugin-specific settings for this block type.
  $form += $this
    ->blockForm($form, $form_state);
  return $form;
}