function BlockPluginTrait::buildConfigurationForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::buildConfigurationForm()
  2. 10 core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::buildConfigurationForm()
  3. 11.x 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()

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

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