* // Finally, build a renderable array from the transformed tree.
* $menu = $menu_tree->build($tree);
*
- * $menu_html = drupal_render($menu);
+ * $menu_html = \Drupal::service('renderer')->render($menu);
* @endcode
*
* @}
* as described above.
* @param string $route_name
* The route name of the page.
+ * @param \Drupal\Core\Cache\RefinableCacheableDependencyInterface $cacheability
+ * The cacheability metadata for the current route's local tasks.
*
* @ingroup menu
*/
-function hook_menu_local_tasks_alter(&$data, $route_name) {
+function hook_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) {
// Add a tab linking to node/add to all pages.
$data['tabs'][0]['node.add_page'] = [
],
],
];
+ // The tab we're adding is dependent on a user's access to add content.
+ $cacheability->addCacheTags(['user.permissions']);
}
/**
* The following keys can be altered:
* - text: The link text for the anchor tag. If the hook implementation
* changes this text it needs to preserve the safeness of the original text.
- * Using t() or \Drupal\Component\Utility\SafeMarkup::format() with
+ * Using t() or \Drupal\Component\Render\FormattableMarkup with
* @placeholder is recommended as this will escape the original text if
* necessary. If the resulting text is not marked safe it will be escaped.
* - url_is_active: Whether or not the link points to the currently active