I am using Drupal 8. I have a content type "hotel". I would like to change the default tab name "View" only for this content type "hotel". I can change the default tab name "View" by mymodule.links.task.yml (please see below code), but it applies to all content types.

  route_name: entity.node.canonical
  base_route: entity.node.canonical
  title: 'Summary'

So how do I change the default tab name "View" ONLY for a content type?


In your theme open file THEMENAME.theme, and the add code below:

function MYTHEME_preprocess_menu_local_task(&$variables) {
  if (isset($variables['element']['#link']['title']) && $variables['element']['#link']['title'] == 'View') {
    $node = \Drupal::request()->attributes->get('node');
    if ($node && $node->getType() == 'hotel') {
      $variables['link']['#title'] = t('Hotel View');

Clear all cache and see result.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.