1

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.

entity.node.canonical:
  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?

2

In your theme open file THEMENAME.theme, example in my case THEMENAME is bartik and file is bartik.theme add code below:

function bartik_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.