You are here

protected static function ParagraphViewModeWidget::getAvailableViewModes 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::getAvailableViewModes()

Getter for available view modes in paragraph entity type.

Return value

array Associative array of view mode machine names and labels.

2 calls to ParagraphViewModeWidget::getAvailableViewModes()
ParagraphViewModeWidget::defaultSettings in src/Plugin/Field/FieldWidget/ParagraphViewModeWidget.php
Defines the default settings for this plugin.
ParagraphViewModeWidget::getEnabledViewModes in src/Plugin/Field/FieldWidget/ParagraphViewModeWidget.php
Getter for enabled view modes.

File

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

Class

ParagraphViewModeWidget
Plugin implementation of the 'paragraph_view_mode' widget.

Namespace

Drupal\paragraph_view_mode\Plugin\Field\FieldWidget

Code

protected static function getAvailableViewModes() {
  $request = \Drupal::request();
  $entity_display_respository = \Drupal::service('entity_display.repository');
  $paragraph_type = self::getParagraphsTypeFromRequest($request);
  $entity_id = StorageManagerInterface::ENTITY_TYPE;
  if ($paragraph_type instanceof ParagraphsType) {
    return $entity_display_respository
      ->getViewModeOptionsByBundle($entity_id, $paragraph_type
      ->id());
  }
  return $entity_display_respository
    ->getViewModeOptions($entity_id);
}