I would like to change the Edit tab from Edit to Edit Client. The content type is Client.

I tried using the following code in the bartik.theme file in the web/core/themes directory (running drupal 8.5.4).

function bartik_preprocess_menu_local_task(&$variables) {
  if (isset($variables['element']['#link']['title']) && $variables['element']['#link']['title'] == 'Edit') {
    $node = \Drupal::request()->attributes->get('node');
    if ($node && $node->getType() == 'client') {
      $variables['link']['#title'] = t('Edit Client');
  • 1
    I hope you're just using Bartik here for testing purposes. You're not suppose to touch anything in /core folder. Because when you update Drupal, it will override everything inside the /core folder; thus, you will lose all your changes. If you like Bartik and want to use it as your theme, then you should create a new theme and use Bartik as your base theme. – No Sssweat Jul 6 '18 at 23:05

Use hook_menu_local_tasks_alter see the docs. You can get a dynamic title combining tokens and the translation API.

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.