Skip to content
Snippets Groups Projects

Resolve #2885278 "New 11.x"

Files

@@ -4,6 +4,8 @@
namespace Drupal\node\Hook;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -66,6 +68,35 @@ public function userCancelReassign($edit, UserInterface $account, $method): void
}
}
/**
* Implements hook_menu_local_tasks_alter().
*/
#[Hook('menu_local_tasks_alter')]
public function nodeLocalMenuAlter(&$local_tasks, $route_name, RefinableCacheableDependencyInterface &$cacheability): void {
if ($route_name === 'entity.node.revision') {
// Show the same local tasks on node revision pages as the ones displayed
// on node canonical pages.
$node_canonical_local_tasks = \Drupal::service('plugin.manager.menu.local_task')
->getLocalTasks('entity.node.canonical');
$local_tasks['tabs'][0] = $node_canonical_local_tasks['tabs'];
// Mark the version history local task as active when viewing a node
// revision.
foreach ($local_tasks['tabs'][0] as $route_name => &$tab) {
$tab['#active'] = $route_name === 'entity.node.version_history';
}
$cacheability = CacheableMetadata::createFromObject($cacheability)
->merge($node_canonical_local_tasks['cacheability']);
}
}
/**
* Implements hook_config_translation_info_alter().
*/
#[Hook('config_translation_info_alter')]
public function nodeConfigTranslationInfoAlter(&$info): void {
$info['node_type']['class'] = 'Drupal\node\ConfigTranslation\NodeTypeMapper';
}
/**
* Implements hook_block_alter().
*/
Loading