You are here

public static function ParagraphViewModeWidget::defaultViewModes in Paragraph View Mode 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldWidget/ParagraphViewModeWidget.php \Drupal\paragraph_view_mode\Plugin\Field\FieldWidget\ParagraphViewModeWidget::defaultViewModes()

Ajax callback for updating the default view mode options.

Parameters

array $form: Form structure.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Return value

array Default view mode form element.

File

src/Plugin/Field/FieldWidget/ParagraphViewModeWidget.php, line 119

Class

ParagraphViewModeWidget
Plugin implementation of the 'paragraph_view_mode' widget.

Namespace

Drupal\paragraph_view_mode\Plugin\Field\FieldWidget

Code

public static function defaultViewModes(array $form, FormStateInterface $form_state) {
  $checkboxes = $form_state
    ->getTriggeringElement();
  $element = NestedArray::getValue($form, array_slice($checkboxes['#array_parents'], 0, count($checkboxes['#array_parents']) - 2));
  $options = array_intersect_key($element['view_modes']['#options'], $element['view_modes']['#value']);
  $element['default_view_mode']['#options'] = empty($options) ? $element['view_modes']['#options'] : $options;
  return $element['default_view_mode'];
}