I'm attempting develop a module in drupal-8 that provides a link to an external password reset system. Specifically on the login page I'd like a reset my password link that points to a link such as https://reset.my.password/

I've tried adding my module.links.task.yml file. What else do I have to create to add an external link?

  • 1
    links.task.yml files are for defining local tasks. It is not clear if that is the kind of link you are looking to achieve? Where do you want the link to be displayed? To whom? – stevekeiretsu Feb 12 '20 at 1:16

There seems to be very little information on this matter, maybe it's not that common to try to achieve something like this, but I stumbled across this thread while searching for a solution and I'd like to add my thoughts.

The comments stating that links.task.yml is for local tasks is right, but when it comes to external links, it's not that simple. As far as I know, you need routing to add links that way, and routing is for internal links, right?

So in the end I did it this way in Drupal 9:

  function my_module_menu_local_tasks_alter(&$data, $route_name) {    
    $data['tabs'][0]['node.extra_tab'] = array(
      '#theme' => 'menu_local_task',
      '#link' => array(
        'title' => t('Extra tab'),
        'url' => Url::fromUri('https://theurl.com', array('attributes' => array('target' => '_blank'))),
        'localized_options' => array(
          'attributes' => array(
            'title' => t('Extra tab'),

You can also add something like if ($route_name == 'entity.node.canonical') to narrow it down and also if (\Drupal::routeMatch()->getParameter('node') == 'my_content_type') in case you want this to work only on certain content type(s).


You can try hook_menu_local_tasks_alter

 * Implements hook_menu_local_tasks_alter().
function mymodule_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
  foreach ($data['tabs'] as &$tab){
    $tab['routing_name']['#link']['url'] = Url::fromUri('https://reset.my.password/');
  • See the comment on the question. – kiamlaluno Feb 12 '20 at 6:25

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.