Implements hook_menu_local_tasks_alter().
function design_test_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if ($router_item['number_parts'] > 2 && strpos($root_path, 'design_test/') === 0) {
$actions =& $data['actions']['output'];
// Determine the currently selected theme, if any.
$selected_theme = drupal_container()
->get('request')->query
->get('theme');
$default_theme = config('system.theme')
->get('default');
// Expand all enabled themes into action links.
$themes = list_themes();
foreach ($themes as $name => $theme) {
$action = array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => $theme->info['name'],
'href' => $router_item['href'],
'localized_options' => array(
'html' => FALSE,
),
),
'#active' => $selected_theme == $name,
);
// Only add the theme-switcher query parameter for all non-default themes.
if ($name != $default_theme) {
$action['#link']['localized_options']['query']['theme'] = $name;
}
$actions[] = $action;
}
if ($themes > 1) {
$data['actions']['count']++;
}
}
}