function logouttab_menu_local_tasks_alter in Logout Tab 8
Implements hook_menu_local_tasks_alter().
Changes weight and access for the 'Log out' tab on the user page.
File
- ./
logouttab.module, line 36 - Adds a logout tab to the user page.
Code
function logouttab_menu_local_tasks_alter(&$data, $route_name, &$cacheability) {
if (isset($data['tabs'][0]['entity.user.logouttab'])) {
$tab_data =& $data['tabs'][0]['entity.user.logouttab'];
$link_params = $tab_data['#link']['url']
->getRouteParameters();
$tab_data['#access'] = $link_params['user'] == \Drupal::currentUser()
->id();
if ($tab_data['#access']) {
// Change tab weight to user configured.
$config = \Drupal::config('logouttab.settings');
$tab_data['#weight'] = $config
->get('weight');
// Make cache dependent on config.
$cacheability = $cacheability
->merge(CacheableMetadata::createFromObject($config));
}
}
}