BlockBase.php

Same filename in other branches
  1. 8.9.x core/lib/Drupal/Core/Block/BlockBase.php
  2. 10 core/lib/Drupal/Core/Block/BlockBase.php
  3. 11.x core/lib/Drupal/Core/Block/BlockBase.php

Namespace

Drupal\Core\Block

File

core/lib/Drupal/Core/Block/BlockBase.php

View source
<?php

namespace Drupal\Core\Block;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginTrait;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\PluginWithFormsInterface;
use Drupal\Core\Plugin\PreviewAwarePluginInterface;
use Drupal\Core\Render\PreviewFallbackInterface;

/**
 * Defines a base block implementation that most blocks plugins will extend.
 *
 * This abstract class provides the generic block configuration form, default
 * block settings, and handling for general user-defined block visibility
 * settings.
 *
 * @ingroup block_api
 */
abstract class BlockBase extends PluginBase implements BlockPluginInterface, PluginWithFormsInterface, PreviewAwarePluginInterface, PreviewFallbackInterface, ContextAwarePluginInterface {
    use BlockPluginTrait {
        buildConfigurationForm as traitBuildConfigurationForm;
    }
    use ContextAwarePluginTrait;
    use ContextAwarePluginAssignmentTrait;
    
    /**
     * {@inheritdoc}
     */
    public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
        $form = $this->traitBuildConfigurationForm($form, $form_state);
        // Add context mapping UI form elements.
        $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
        $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
        return $form;
    }

}

Classes

Title Deprecated Summary
BlockBase Defines a base block implementation that most blocks plugins will extend.

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