function FieldBlock::getApplicablePluginOptions

Same name in other branches
  1. 9 core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::getApplicablePluginOptions()
  2. 8.9.x core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::getApplicablePluginOptions()
  3. 11.x core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::getApplicablePluginOptions()

Returns an array of applicable formatter options for a field.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

Return value

array An array of applicable formatter options.

See also

\Drupal\field_ui\Form\EntityDisplayFormBase::getApplicablePluginOptions()

1 call to FieldBlock::getApplicablePluginOptions()
FieldBlock::blockForm in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php

File

core/modules/layout_builder/src/Plugin/Block/FieldBlock.php, line 369

Class

FieldBlock
Provides a block that renders a field from an entity.

Namespace

Drupal\layout_builder\Plugin\Block

Code

protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition) {
    $options = $this->formatterManager
        ->getOptions($field_definition->getType());
    $applicable_options = [];
    foreach ($options as $option => $label) {
        $plugin_class = DefaultFactory::getPluginClass($option, $this->formatterManager
            ->getDefinition($option));
        if ($plugin_class::isApplicable($field_definition)) {
            $applicable_options[$option] = $label;
        }
    }
    return $applicable_options;
}

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