You are here

protected function HeadingWidget::formElementSize in Heading field 8

Create the size form element.

The heading size select will be hidden if there is only one heading size allowed.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field items.

int $delta: The current field delta.

Return value

array Form element render array.

1 call to HeadingWidget::formElementSize()
HeadingWidget::formElement in src/Plugin/Field/FieldWidget/HeadingWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/HeadingWidget.php, line 66

Class

HeadingWidget
Heading widget for the heading field type.

Namespace

Drupal\heading\Plugin\Field\FieldWidget

Code

protected function formElementSize(FieldItemListInterface $items, $delta) {
  $size_options = $this
    ->getTypes();
  if (count($size_options) === 1) {
    reset($size_options);
    return [
      '#type' => 'value',
      '#value' => key($size_options),
    ];
  }
  $size_options_keys = array_keys($size_options);
  $size_default = isset($items[$delta]->size) ? $items[$delta]->size : reset($size_options_keys);
  return [
    '#type' => 'select',
    '#title' => $this
      ->t('Size'),
    '#default_value' => $size_default,
    '#options' => $size_options,
  ];
}