You are here

protected function FieldBlock::getFormatterOptions in Field as Block 8.2

Returns field formatter names.

Parameters

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

Return value

array Array of formatter names keyed by field type.

1 call to FieldBlock::getFormatterOptions()
FieldBlock::blockForm in src/Plugin/Block/FieldBlock.php

File

src/Plugin/Block/FieldBlock.php, line 155

Class

FieldBlock
Provides a fieldblock.

Namespace

Drupal\fieldblock\Plugin\Block

Code

protected function getFormatterOptions(FieldDefinitionInterface $field_definition) {
  $options = $this->formatterPluginManager
    ->getOptions($field_definition
    ->getType());
  foreach ($options as $id => $label) {
    $definition = $this->formatterPluginManager
      ->getDefinition($id, FALSE);
    $formatter_plugin_class = isset($definition['class']) ? $definition['class'] : NULL;
    $applicable = $formatter_plugin_class instanceof FormatterInterface && $formatter_plugin_class::isApplicable($field_definition);
    if ($applicable) {
      unset($options[$id]);
    }
  }
  return $options;
}