Browse Source

only change view mode for the current node (#104)

* only change view mode for the current node
* fix coder issue
pull/729/head
Paul Pound 6 years ago committed by Seth Shaw
parent
commit
ef2e42170e
  1. 8
      islandora.module

8
islandora.module

@ -257,7 +257,9 @@ function islandora_entity_view_mode_alter(&$view_mode, EntityInterface $entity)
// ContextReaction. // ContextReaction.
$storage = \Drupal::service('entity_type.manager')->getStorage('entity_view_mode'); $storage = \Drupal::service('entity_type.manager')->getStorage('entity_view_mode');
$context_manager = \Drupal::service('context.manager'); $context_manager = \Drupal::service('context.manager');
$current_entity = \Drupal::routeMatch()->getParameter('node');
$current_id = ($current_entity instanceof NodeInterface) ? $current_entity->id() : NULL;
if (isset($current_id) && $current_id == $entity->id()) {
foreach ($context_manager->getActiveReactions('\Drupal\islandora\Plugin\ContextReaction\ViewModeAlterReaction') as $reaction) { foreach ($context_manager->getActiveReactions('\Drupal\islandora\Plugin\ContextReaction\ViewModeAlterReaction') as $reaction) {
// Construct the new view mode's machine name. // Construct the new view mode's machine name.
$entity_type = $entity->getEntityTypeId(); $entity_type = $entity->getEntityTypeId();
@ -273,7 +275,9 @@ function islandora_entity_view_mode_alter(&$view_mode, EntityInterface $entity)
} }
else { else {
// Otherwise, leave it be, but log a message. // Otherwise, leave it be, but log a message.
\Drupal::logger('islandora')->info("EntityViewMode $machine_name does not exist. View mode cannot be altered."); \Drupal::logger('islandora')
->info("EntityViewMode $machine_name does not exist. View mode cannot be altered.");
}
} }
} }
} }

Loading…
Cancel
Save