- Issue created by @wotnak
- π΅π±Poland wotnak
Created merge request with hook_menu_local_tasks_alter implementation that removes project logs tab for all route matches that don't have project plan in params. This results in 'Logs' tab being visible only on project plans and not on other plan types.
- Status changed to Needs review
9 months ago 5:33pm 29 March 2024 - πΊπΈUnited States paul121 Spokane, WA
Thanks @wotnak! In the past we've solved this issue of hiding local tasks by making the associated route have an access check result/response of 4xx. I've done this in farmOS core and some contrib modules. With your implementation I worry that this might entirely remove the task definition? Unless they are cached for each entity/page? And even if they are, it might just be easier to have a single task that is always visible and use access checking to determine if the task is shown?
.. In fact, it looks like I had already implemented my approach in this module via a Route subscriber: https://git.drupalcode.org/project/farm_project_plan/-/blob/1.x/src/Rout...
BUT
_entity_bundles
is deprecated and must have been removed from Drupal 10, now we should usebundle
https://www.drupal.org/node/3155569 βI think that would solve it. What do you think of this approach?
- π΅π±Poland wotnak
Local tasks (tabs) are by default cached per route, user.permissions and specific entity, for example test project and crop plan I was testing this changes have following CacheableMetadata
Using hook_menu_local_tasks_alter to remove tab under specific conditions is safe and there's even an example in drupal core https://git.drupalcode.org/project/drupal/-/blob/820d76b2c71d22132796969....But I think you're right that replacing _entity_bundles restriction with bundle key in route param would be in this case a better approach. Updated the MR to use this approach, it seems to work well.
-
paul121 β
committed f5d4a0b7 on 1.x authored by
wotnak β
Issue #3437050 by wotnak: Logs tab is visible on other plan types
-
paul121 β
committed f5d4a0b7 on 1.x authored by
wotnak β
- Status changed to Fixed
9 months ago 9:06pm 29 March 2024 - πΊπΈUnited States paul121 Spokane, WA
That caching makes sense. Thanks for sharing. Will keep this in mind for future cases. Thanks again @wotnak!
- πΊπΈUnited States paul121 Spokane, WA
Made a new 1.1.1 release with this
Automatically closed - issue fixed for 2 weeks with no activity.