You are here

private function MenuItemExtrasViewModeSelectorSelect::getFromWidgetViewModes in Menu Item Extras 8.2

Extracts from form state menu link view modes.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: Array of default values for this field.

int $delta: The order of this item in the array of sub-elements (0, 1, 2, etc.).

array $element: A form element array containing basic properties for the widget.

array $form: The form structure where widgets are being attached to. This might be a full form structure, or a sub-element of a larger form.

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

Return value

array The view modes array of menu link.

See also

\Drupal\Core\Field\WidgetInterface::formElement()

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

File

src/Plugin/Field/FieldWidget/MenuItemExtrasViewModeSelectorSelect.php, line 93

Class

MenuItemExtrasViewModeSelectorSelect
Base class for the menu item extras view mode widget.

Namespace

Drupal\menu_item_extras\Plugin\Field\FieldWidget

Code

private function getFromWidgetViewModes(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  $bundle = $storage['form_display']
    ->getTargetBundle();
  $entity_type = $storage['form_display']
    ->getTargetEntityTypeId();

  // Get all view modes for the current bundle.
  $view_modes = $this->entityDisplayRepository
    ->getViewModeOptionsByBundle($entity_type, $bundle);
  if (count($view_modes) === 0) {
    $view_modes['default'] = $this
      ->t('Default');
  }
  return $view_modes;
}