You are here

function ds_switch_view_mode_entity_view_mode_alter in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 modules/ds_switch_view_mode/ds_switch_view_mode.module \ds_switch_view_mode_entity_view_mode_alter()
  2. 8.3 modules/ds_switch_view_mode/ds_switch_view_mode.module \ds_switch_view_mode_entity_view_mode_alter()

Implements hook_entity_view_mode_alter().

File

modules/ds_switch_view_mode/ds_switch_view_mode.module, line 38
Display Suite Switch View mode.

Code

function ds_switch_view_mode_entity_view_mode_alter(&$view_mode, EntityInterface $entity, $context) {
  if ($entity
    ->getEntityTypeId() == 'node' && node_is_page($entity) && !empty($entity->ds_switch->value) && $view_mode == 'full') {
    $original_view_mode = $view_mode;
    $view_mode = $entity->ds_switch->value;
    \Drupal::moduleHandler()
      ->alter('ds_switch_view_mode', $view_mode, $original_view_mode, $entity);
  }
}