You are here

public function ParagraphsViewmodeBehavior::entityViewModeAlter in Paragraphs View Modes 8

Allow plugin to alter the paragraph view mode.

Parameters

string $view_mode: The current view mode.

\Drupal\paragraphs\ParagraphInterface $paragraph: The paragraph.

array $context: Additional context information.

Return value

mixed The new view mode.

Overrides ParagraphsViewmodeBehaviorInterface::entityViewModeAlter

File

src/Plugin/paragraphs/Behavior/ParagraphsViewmodeBehavior.php, line 171

Class

ParagraphsViewmodeBehavior
Class ParagraphsViewmodeBehavior.

Namespace

Drupal\paragraphs_viewmode\Plugin\paragraphs\Behavior

Code

public function entityViewModeAlter(&$view_mode, ParagraphInterface $paragraph, array $context) {
  $override_mode = $this->configuration['override_mode'];
  $new_view_mode = $paragraph
    ->getBehaviorSetting($this->pluginId, 'view_mode', $this->configuration['override_default']);
  if ($view_mode != $override_mode || $override_mode == $new_view_mode) {
    return;
  }
  $view_mode = $new_view_mode;
}