You are here

public function GridWidget::getViewModeOptions in Paragraphs grid 8

Returns view modes as options for a select form field.

Parameters

bool $filtered: If view modes should be filtered from excluded view modes or not.

Return value

array View mode options for a select form field.

2 calls to GridWidget::getViewModeOptions()
GridWidget::formElement in src/Plugin/Field/FieldWidget/GridWidget.php
Returns the form for a single field widget.
GridWidget::settingsForm in src/Plugin/Field/FieldWidget/GridWidget.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/GridWidget.php, line 210

Class

GridWidget
Plugin implementation of the 'grid_widget' widget.

Namespace

Drupal\paragraphs_grid\Plugin\Field\FieldWidget

Code

public function getViewModeOptions($filtered = TRUE) {
  $type = $this->fieldDefinition
    ->getTargetEntityTypeId();
  $bundle = $this->fieldDefinition
    ->getTargetBundle();
  $view_modes = $filtered ? [
    '' => $this
      ->t('default'),
  ] : [];
  $view_modes += $this->entityDisplayRepository
    ->getViewModeOptionsByBundle($type, $bundle);
  unset($view_modes['default']);
  if ($filtered) {
    foreach ($this
      ->getSetting('excluded_view_modes') as $exclude) {
      unset($view_modes[$exclude]);
    }
  }
  return $view_modes;
}