You are here

protected function FieldFormatterBase::getSettingFromFormState in (Entity Reference) Field Formatters 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::getSettingFromFormState()
  2. 3.x src/Plugin/Field/FieldFormatter/FieldFormatterBase.php \Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase::getSettingFromFormState()

Helper function to retrieve the $setting from the $form_state.

Parameters

Drupal\Core\Form\FormStateInterface $form_state: The form state object.

string $setting: The setting key to retrieve.

1 call to FieldFormatterBase::getSettingFromFormState()
FieldFormatterWithInlineSettings::settingsForm in src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/FieldFormatterBase.php, line 180

Class

FieldFormatterBase
Base class for field formatters.

Namespace

Drupal\field_formatter\Plugin\Field\FieldFormatter

Code

protected function getSettingFromFormState(FormStateInterface $form_state, $setting) {
  $field_name = $this->fieldDefinition
    ->getName();
  if ($form_state
    ->hasValue([
    'fields',
    $field_name,
    'settings_edit_form',
    'settings',
    $setting,
  ])) {
    return $form_state
      ->getValue([
      'fields',
      $field_name,
      'settings_edit_form',
      'settings',
      $setting,
    ]);
  }
  return $this
    ->getSetting($setting);
}