|
|
@ -257,23 +257,27 @@ 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'); |
|
|
|
foreach ($context_manager->getActiveReactions('\Drupal\islandora\Plugin\ContextReaction\ViewModeAlterReaction') as $reaction) { |
|
|
|
$current_id = ($current_entity instanceof NodeInterface) ? $current_entity->id() : NULL; |
|
|
|
// Construct the new view mode's machine name. |
|
|
|
if (isset($current_id) && $current_id == $entity->id()) { |
|
|
|
$entity_type = $entity->getEntityTypeId(); |
|
|
|
foreach ($context_manager->getActiveReactions('\Drupal\islandora\Plugin\ContextReaction\ViewModeAlterReaction') as $reaction) { |
|
|
|
$mode = $reaction->execute(); |
|
|
|
// Construct the new view mode's machine name. |
|
|
|
$machine_name = "$entity_type.$mode"; |
|
|
|
$entity_type = $entity->getEntityTypeId(); |
|
|
|
|
|
|
|
$mode = $reaction->execute(); |
|
|
|
// Try to load it. |
|
|
|
$machine_name = "$entity_type.$mode"; |
|
|
|
$new_mode = $storage->load($machine_name); |
|
|
|
|
|
|
|
|
|
|
|
// Try to load it. |
|
|
|
// If successful, alter the view mode. |
|
|
|
$new_mode = $storage->load($machine_name); |
|
|
|
if ($new_mode) { |
|
|
|
|
|
|
|
$view_mode = $mode; |
|
|
|
// If successful, alter the view mode. |
|
|
|
} |
|
|
|
if ($new_mode) { |
|
|
|
else { |
|
|
|
$view_mode = $mode; |
|
|
|
// Otherwise, leave it be, but log a message. |
|
|
|
} |
|
|
|
\Drupal::logger('islandora')->info("EntityViewMode $machine_name does not exist. View mode cannot be altered."); |
|
|
|
else { |
|
|
|
|
|
|
|
// Otherwise, leave it be, but log a message. |
|
|
|
|
|
|
|
\Drupal::logger('islandora') |
|
|
|
|
|
|
|
->info("EntityViewMode $machine_name does not exist. View mode cannot be altered."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|