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).