You are here

public function FieldBlock::formatterSettingsProcessCallback in Drupal 9

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

Render API callback: builds the formatter settings elements.

File

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

Class

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

Namespace

Drupal\layout_builder\Plugin\Block

Code

public function formatterSettingsProcessCallback(array &$element, FormStateInterface $form_state, array &$complete_form) {
  if ($formatter = $this
    ->getFormatter($element['#parents'], $form_state)) {
    $element['settings_wrapper']['settings'] = $formatter
      ->settingsForm($complete_form, $form_state);
    $element['settings_wrapper']['settings']['#parents'] = array_merge($element['#parents'], [
      'settings',
    ]);
    $element['settings_wrapper']['third_party_settings'] = $this
      ->thirdPartySettingsForm($formatter, $this
      ->getFieldDefinition(), $complete_form, $form_state);
    $element['settings_wrapper']['third_party_settings']['#parents'] = array_merge($element['#parents'], [
      'third_party_settings',
    ]);
    FormHelper::rewriteStatesSelector($element['settings_wrapper'], "fields[{$this->fieldName}][settings_edit_form]", 'settings[formatter]');

    // Store the array parents for our element so that we can retrieve the
    // formatter settings in our AJAX callback.
    $form_state
      ->set('field_block_array_parents', $element['#array_parents']);
  }
  return $element;
}