You are here

protected function FieldBlock::getFormatter in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Plugin/Block/FieldBlock.php \Drupal\layout_builder\Plugin\Block\FieldBlock::getFormatter()

Gets the formatter object.

Parameters

array $parents: The #parents of the element representing the formatter.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Field\FormatterInterface The formatter object.

1 call to FieldBlock::getFormatter()
FieldBlock::formatterSettingsProcessCallback in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
Render API callback: builds the formatter settings elements.

File

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

Class

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

Namespace

Drupal\layout_builder\Plugin\Block

Code

protected function getFormatter(array $parents, FormStateInterface $form_state) {

  // Use the processed values, if available.
  $configuration = NestedArray::getValue($form_state
    ->getValues(), $parents);
  if (!$configuration) {

    // Next check the raw user input.
    $configuration = NestedArray::getValue($form_state
      ->getUserInput(), $parents);
    if (!$configuration) {

      // If no user input exists, use the default values.
      $configuration = $this
        ->getConfiguration()['formatter'];
    }
  }
  return $this->formatterManager
    ->getInstance([
    'configuration' => $configuration,
    'field_definition' => $this
      ->getFieldDefinition(),
    'view_mode' => EntityDisplayBase::CUSTOM_MODE,
    'prepare' => TRUE,
  ]);
}