You are here

public function HeadingItem::fieldSettingsForm in Heading field 8

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::fieldSettingsForm

File

src/Plugin/Field/FieldType/HeadingItem.php, line 91

Class

HeadingItem
Provides a field type "heading" containing a heading type and text.

Namespace

Drupal\heading\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $element = [];
  $default_settings = self::defaultFieldSettings();
  $default_label_settings = $this
    ->getSetting('label');
  $default_label = !empty($default_label_settings) ? $default_label_settings : $default_settings['label'];
  $element['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#description' => $this
      ->t('Set the form label for the text field of the heading.'),
    '#default_value' => $default_label,
  ];
  $allowed_sizes_settings = $this
    ->getSetting('allowed_sizes');
  $default_allowed_sizes = is_array($allowed_sizes_settings) && !empty($allowed_sizes_settings) ? $allowed_sizes_settings : $default_settings['allowed_sizes'];
  $element['allowed_sizes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Allowed sizes'),
    '#description' => $this
      ->t('Limit the allowed heading sizes.'),
    '#options' => $this
      ->getSizes(),
    '#default_value' => $default_allowed_sizes,
  ];
  return $element;
}