class Blocks in Block field 8
Provides a 'categories' BlockFieldSection.
Plugin annotation
@BlockFieldSelection(
  id = "blocks",
  label = @Translation("Blocks"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface- class \Drupal\block_field\BlockFieldSelectionBase implements BlockFieldSelectionInterface, ConfigurableInterface- class \Drupal\block_field\Plugin\block_field\BlockFieldSelection\Blocks uses DependencySerializationTrait, StringTranslationTrait
 
 
- class \Drupal\block_field\BlockFieldSelectionBase implements BlockFieldSelectionInterface, ConfigurableInterface
Expanded class hierarchy of Blocks
1 string reference to 'Blocks'
- Blocks::buildConfigurationForm in src/Plugin/ block_field/ BlockFieldSelection/ Blocks.php 
- Form constructor.
File
- src/Plugin/ block_field/ BlockFieldSelection/ Blocks.php, line 18 
Namespace
Drupal\block_field\Plugin\block_field\BlockFieldSelectionView source
class Blocks extends BlockFieldSelectionBase {
  use DependencySerializationTrait;
  use StringTranslationTrait;
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'plugin_ids' => [],
    ] + parent::defaultConfiguration();
  }
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    /** @var \Drupal\block_field\BlockFieldManagerInterface $block_field_manager */
    $block_field_manager = \Drupal::service('block_field.manager');
    $definitions = $block_field_manager
      ->getBlockDefinitions();
    foreach ($definitions as $plugin_id => $definition) {
      $options[$plugin_id] = [
        [
          'category' => (string) $definition['category'],
        ],
        [
          'label' => $definition['admin_label'] . ' (' . $plugin_id . ')',
        ],
        [
          'provider' => $definition['provider'],
        ],
      ];
    }
    $default_value = !empty($this
      ->getConfiguration()['plugin_ids']) ? $this
      ->getConfiguration()['plugin_ids'] : array_keys($options);
    $form['blocks'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Blocks'),
      '#description' => $this
        ->t('Please select available blocks.'),
      '#open' => empty($this
        ->getConfiguration()['plugin_ids']),
      '#process' => [
        [
          $this,
          'formProcessMergeParent',
        ],
      ],
    ];
    $form['blocks']['plugin_ids'] = [
      '#type' => 'tableselect',
      '#header' => [
        $this
          ->t('Category'),
        $this
          ->t('Label/ID'),
        $this
          ->t('Provider'),
      ],
      '#options' => $options,
      '#js_select' => TRUE,
      '#required' => TRUE,
      '#empty' => $this
        ->t('No blocks are available.'),
      '#element_validate' => [
        [
          get_called_class(),
          'validatePluginIds',
        ],
      ],
      '#default_value' => array_combine($default_value, $default_value),
    ];
    return $form;
  }
  /**
   * Validates plugin_ids table select element.
   *
   * @param array $element
   *   A form element.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The $form_state from complete form.
   * @param array $complete_form
   *   Complete parent form.
   *
   * @return array
   *   Returns element with validated plugin ids.
   */
  public static function validatePluginIds(array &$element, FormStateInterface $form_state, array &$complete_form) {
    $value = array_filter($element['#value']);
    if (array_keys($element['#options']) == array_keys($value)) {
      $form_state
        ->setValueForElement($element, []);
    }
    else {
      $form_state
        ->setValueForElement($element, $value);
    }
    return $element;
  }
  /**
   * {@inheritdoc}
   */
  public function getReferenceableBlockDefinitions() {
    $block_field_manager = \Drupal::service('block_field.manager');
    $definitions = $block_field_manager
      ->getBlockDefinitions();
    $values = !empty($this
      ->getConfiguration()['plugin_ids']) ? $this
      ->getConfiguration()['plugin_ids'] : array_keys($definitions);
    $values = array_combine($values, $values);
    return array_intersect_key($definitions, $values);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| BlockFieldSelectionBase:: | public | function | Move settings up a level for easier processing and storage. | |
| BlockFieldSelectionBase:: | public | function | Gets this plugin's configuration. Overrides ConfigurableInterface:: | |
| BlockFieldSelectionBase:: | public | function | Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: | |
| BlockFieldSelectionBase:: | public | function | Form submission handler. Overrides PluginFormInterface:: | |
| BlockFieldSelectionBase:: | public | function | Form validation handler. Overrides PluginFormInterface:: | |
| BlockFieldSelectionBase:: | public | function | Constructs a new selection object. Overrides PluginBase:: | |
| Blocks:: | public | function | Form constructor. Overrides BlockFieldSelectionBase:: | |
| Blocks:: | public | function | Gets default configuration for this plugin. Overrides BlockFieldSelectionBase:: | |
| Blocks:: | public | function | Returns filtered block definitions based on plugin settings. Overrides BlockFieldSelectionInterface:: | |
| Blocks:: | public static | function | Validates plugin_ids table select element. | |
| DependencySerializationTrait:: | protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| DependencySerializationTrait:: | protected | property | An array of service IDs keyed by property name used for serialization. | |
| DependencySerializationTrait:: | public | function | 1 | |
| DependencySerializationTrait:: | public | function | 2 | |
| PluginBase:: | protected | property | Configuration information passed into the plugin. | 1 | 
| PluginBase:: | protected | property | The plugin implementation definition. | 1 | 
| PluginBase:: | protected | property | The plugin_id. | |
| PluginBase:: | constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
| PluginBase:: | public | function | Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: | |
| PluginBase:: | public | function | Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: | |
| PluginBase:: | public | function | Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: | 3 | 
| PluginBase:: | public | function | Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: | |
| PluginBase:: | public | function | Determines if the plugin is configurable. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | 
