5

I'm looking for a way to change the text being displayed in the links on the user account page.

enter image description here

More specifically, I'm trying to change the text "View" and "Edit" to "View Profile" and "Edit Profile". Ideally, I would prefer a solution that allows me to do this in my .theme file via a preprocessor or a hook function.

6

As I know you can't do it in your theme, but it is possible to do in your module.

/**
 * Implements hook_menu_local_tasks_alter().
 */
function mymodule_menu_local_tasks_alter(&$data, $route_name) {
  // Change title for user profile's tabs.
  foreach ($data['tabs'] as &$tabs) {
    foreach ($tabs as &$tab) {
      $route_name = $tab['#link']['url']->getRouteName();
      if ($route_name == 'entity.user.canonical') {
        $tab['#link']['title'] = t('View profile');
      }
      elseif ($route_name == 'entity.user.edit_form') {
        $tab['#link']['title'] = t('Edit profile');
      }
    }
  }
}
5
  • Thank you man. I will try this when I get home and update you. It looks like it should work
    – Adrian
    Feb 26 '16 at 19:20
  • @Adrian Thank you man??? her name is Maria...
    – No Sssweat
    Feb 26 '16 at 23:26
  • @NoSssweat I am Jamaican. Man != "Male" to me. It is just a figure of speech in my country.
    – Adrian
    Feb 27 '16 at 2:45
  • Works perfectly. Respect
    – Adrian
    Feb 27 '16 at 3:01
  • I need to do same thing. but i added the above code i got an error. 'Call to a member function getRouteName() on a non-object in...'
    – TopTomato
    Apr 7 '16 at 15:16
0

There is also a module that could be exactly what you need : Tab Tamer.

2
  • The question was asked for Drupal 8, that module is Drupal 7 only and looks fairly inactive.
    – Kevin
    Mar 1 '16 at 18:09
  • Sorry for that, I did not notice it was for D8.
    – Toki
    Mar 2 '16 at 15:58

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.