Categories
CMS Drupal Mastering Development

hook_menu_local_tasks_alter is not invoked during functional tests

I have an implementation of hook_menu_local_tasks_alter in my module, which works fine on my dev environment, but when I try to run my module using BrowserTestBase the hook is not invoked when visiting a node. Why?

Here is a mock instance of the hook that I’ve set up just to see if the hook is being called:

function implementations_menu_local_tasks_alter(array &$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) {

  throw new Exception('whoops');
}

I’ve ruled out the module not being installed properly, as the other hooks are invoked without issue. Looking at the html produced by BrowserTestBase I can see that some header links are present in the header, but I don’t see any view/edit tabs present in the body of the html. I tried changing BrowserTestBase::$defaultTheme to both 'classy' and 'bartik' with the same result.

ID #21 (Previous | Next)
Called from GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promise\{closure}() line 39
GET request to: http://localhost/node/2
Skip to main content
Status message
Implementation Some Title has been created.
Some Title
Member for
3 seconds
Submitted by p6fNZyQj on Sun, 10/18/2020 - 15:26
Parent Idea
my_idea
Headers:
array (
  'Date' => 'Sun, 18 Oct 2020 04:26:21 GMT',
  'Server' => 'Apache/2.4.38 (Debian)',
  'X-Powered-By' => 'PHP/7.4.11',
  'X-Drupal-Assertion-0' => 'a%3A3%3A%7Bi%3A0%3BO%3A25%3A%22Drupal%5CCore%5CRender%5CMarkup%22%3A1%3A%7Bs%3A9%3A%22%00%2A%00string%22%3Bs%3A217%3A%22The%20signature%20of%20the%20%22Drupal%5CComponent%5CEventDispatcher%5CContainerAwareEventDispatcher%3A%3Adispatch%28%29%22%20method%20should%20be%20updated%20to%20%22dispatch%28%24event%2C%20string%20%24eventName%20%3D%20null%29%22%2C%20not%20doing%20so%20is%20deprecated%20since%20Symfony%204.3.%22%3B%7Di%3A1%3Bs%3A24%3A%22User%20deprecated%20function%22%3Bi%3A2%3Ba%3A3%3A%7Bs%3A8%3A%22function%22%3Bs%3A72%3A%22Symfony%5CComponent%5CEventDispatcher%5CLegacyEventDispatcherProxy%3A%3Adecorate%28%29%22%3Bs%3A4%3A%22file%22%3Bs%3A74%3A%22%2Fopt%2Fdrupal%2Fvendor%2Fsymfony%2Fevent-dispatcher%2FLegacyEventDispatcherProxy.php%22%3Bs%3A4%3A%22line%22%3Bi%3A41%3B%7D%7D',
  'X-Drupal-Assertion-1' => 'a%3A3%3A%7Bi%3A0%3BO%3A25%3A%22Drupal%5CCore%5CRender%5CMarkup%22%3A1%3A%7Bs%3A9%3A%22%00%2A%00string%22%3Bs%3A155%3A%22The%20%22Symfony%5CComponent%5CHttpFoundation%5CFile%5CMimeType%5CMimeTypeGuesser%22%20class%20is%20deprecated%20since%20Symfony%204.3%2C%20use%20%22Symfony%5CComponent%5CMime%5CMimeTypes%22%20instead.%22%3B%7Di%3A1%3Bs%3A24%3A%22User%20deprecated%20function%22%3Bi%3A2%3Ba%3A3%3A%7Bs%3A8%3A%22function%22%3Bs%3A9%3A%22include%28%29%22%3Bs%3A4%3A%22file%22%3Bs%3A76%3A%22%2Fopt%2Fdrupal%2Fvendor%2Fsymfony%2Fhttp-foundation%2FFile%2FMimeType%2FMimeTypeGuesser.php%22%3Bs%3A4%3A%22line%22%3Bi%3A18%3B%7D%7D',
  'X-Drupal-Assertion-2' => 'a%3A3%3A%7Bi%3A0%3BO%3A25%3A%22Drupal%5CCore%5CRender%5CMarkup%22%3A1%3A%7Bs%3A9%3A%22%00%2A%00string%22%3Bs%3A181%3A%22The%20%22Symfony%5CComponent%5CHttpFoundation%5CFile%5CMimeType%5CFileBinaryMimeTypeGuesser%22%20class%20is%20deprecated%20since%20Symfony%204.3%2C%20use%20%22Symfony%5CComponent%5CMime%5CFileBinaryMimeTypeGuesser%22%20instead.%22%3B%7Di%3A1%3Bs%3A24%3A%22User%20deprecated%20function%22%3Bi%3A2%3Ba%3A3%3A%7Bs%3A8%3A%22function%22%3Bs%3A9%3A%22include%28%29%22%3Bs%3A4%3A%22file%22%3Bs%3A86%3A%22%2Fopt%2Fdrupal%2Fvendor%2Fsymfony%2Fhttp-foundation%2FFile%2FMimeType%2FFileBinaryMimeTypeGuesser.php%22%3Bs%3A4%3A%22line%22%3Bi%3A18%3B%7D%7D',
  'X-Drupal-Assertion-3' => 'a%3A3%3A%7Bi%3A0%3BO%3A25%3A%22Drupal%5CCore%5CRender%5CMarkup%22%3A1%3A%7Bs%3A9%3A%22%00%2A%00string%22%3Bs%3A177%3A%22The%20%22Symfony%5CComponent%5CHttpFoundation%5CFile%5CMimeType%5CFileinfoMimeTypeGuesser%22%20class%20is%20deprecated%20since%20Symfony%204.3%2C%20use%20%22Symfony%5CComponent%5CMime%5CFileinfoMimeTypeGuesser%22%20instead.%22%3B%7Di%3A1%3Bs%3A24%3A%22User%20deprecated%20function%22%3Bi%3A2%3Ba%3A3%3A%7Bs%3A8%3A%22function%22%3Bs%3A9%3A%22include%28%29%22%3Bs%3A4%3A%22file%22%3Bs%3A84%3A%22%2Fopt%2Fdrupal%2Fvendor%2Fsymfony%2Fhttp-foundation%2FFile%2FMimeType%2FFileinfoMimeTypeGuesser.php%22%3Bs%3A4%3A%22line%22%3Bi%3A18%3B%7D%7D',
  'Cache-Control' => 'must-revalidate, no-cache, private',
  'X-Drupal-Dynamic-Cache' => 'MISS',
  'Link' => '<http://localhost/node/2>; rel="canonical";<http://localhost/node/2>; rel="shortlink";<http://localhost/node/2/delete>; rel="delete-form";<http://localhost/admin/content/node/delete?node=2>; rel="delete-multiple-form";<http://localhost/node/2/edit>; rel="edit-form";<http://localhost/node/2/revisions>; rel="version-history";<http://localhost/node/2>; rel="revision"',
  'X-UA-Compatible' => 'IE=edge',
  'Content-language' => 'en',
  'X-Content-Type-Options' => 'nosniff',
  'X-Frame-Options' => 'SAMEORIGIN',
  'X-Drupal-Cache-Tags' => 'http_response node:1 node:2 node_view rendered user:2 user_view',
  'X-Drupal-Cache-Contexts' => 'languages:language_interface theme timezone url.query_args:_wrapper_format url.site user.permissions user.roles:anonymous',
  'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT',
  'X-Generator' => 'Drupal 9 (https://www.drupal.org)',
  'Vary' => 'Accept-Encoding',
  'Transfer-Encoding' => 'chunked',
  'Content-Type' => 'text/html; charset=UTF-8',
)

How can I invoke hook_menu_local_tasks_alter from a functional test?

Leave a Reply

Your email address will not be published. Required fields are marked *