Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Page Manager in Drupal 7 allows you to configure a menu link for a page, this can be either a Tab (Local Task/Default Local Task), a Menu Item or a Local Action.
I suggest we look at how views provides this functionality a use that.
Comment | File | Size | Author |
---|---|---|---|
#33 | page_manager-2273531-33-local-tasks.patch | 22.33 KB | geek-merlin |
Comments
Comment #1
tim.plunkettLocal tasks and actions are plugins, and have stable APIs.
Menu links are currently entities, but are in flux: #2227441: New plan, Phase 1:Review the architecture and overall implementation proposal for menu links as plugins
I think they should be split to another issue.
Comment #2
rlmumfordI've started working on this, hopefully will have a patch up this evening.
Comment #3
rlmumfordHere's a patch. No tests yet, but both local actions and local tasks should work work.
Comment #4
rlmumfordRerolled against head.
Comment #5
tim.plunkettUghhhh I *hate* that we have to do this. /me shakes fist at core
Couldn't these be combined?
Yeahhhh this is tricky. If you look at PageManagerRoutes, we do work to ensure that existing pages are properly taken over.
Do we actually need to do this? In RouteParamContext I have
$routes = $this->routeProvider->getRoutesByPattern($page->getPath())->all();
I think we should mimic Views' RouteSubscriber and encapsulate this in a protected method, storing them between the two methods.
Let's go with tests next, it will help clarify what we have covered and what we still need.
@rlmumford++
Comment #6
rlmumfordHere's a patch with some tests. I think they're going to fail, but the tests already in 8.x-1.x fail on my local.
Comment #7
tim.plunkettThis still needs to address my comments from #5. Unassigning for now since there is a sprint coming up, but @rlmumford if you want it back, assign it back.
Comment #8
blueminds CreditAttribution: blueminds commentedGoing to work on this issue as part of the layout sprint https://groups.drupal.org/node/423448
Comment #9
blueminds CreditAttribution: blueminds commentedAddressed #5.2/4/5 Not sure what to do with #5.3
Comment #10
cgalli CreditAttribution: cgalli commentedInstalled and tested.
Works well, based on url/paths. Can be applied on own default paths (pm/; pm/tab1; pm/tab2) or on existing ones (admin/tab1). It also works with wildcards /node/%/local1).
For local actions it should be possible to attach them to several paths (analog to the local_action.yml) . This could be achieved by adding a path list or pattern list to the menu definition.
And it needs some help text/documentation to be understood by the user.
Comment #11
blueminds CreditAttribution: blueminds commentedImplemented the ability to attach an action link to multiple pages. See screenshot for the UX details.
Comment #12
blueminds CreditAttribution: blueminds commentedComment #13
rlmumfordRerolled against head. (Patch no longer applied)
Comment #14
rlmumfordRemove some things that got muddled in the re-base.
Comment #15
rlmumfordHere's a patch that stores the route names in a state variable so that they can be reused in the the Local Task and Local Action derivatives. This is how views solves the same problem.
Comment #17
rlmumfordThis is weird. The tests passed locally for me.
Comment #18
rlmumfordTry this
Comment #19
rlmumfordComment #20
tim.plunkettReally sorry for letting this sit. It needs a reroll now, unfortunately.
Comment #21
sylus CreditAttribution: sylus commentedDoes the following code still looks like this with all the event subscriber work? Looking around core I still don't see a better way?
I'd love to tackle this issue but would need some instruction on how best to approach this given the codebase is entirely different since this was last looked at.
Comment #22
lucas.constantino CreditAttribution: lucas.constantino at Taller commentedAny news on this? This is something badly needed :) I also tried to figure out how to reroll, but code base is completely different :(
Comment #23
cosolom CreditAttribution: cosolom commentedComment #24
saemideluxe CreditAttribution: saemideluxe commentedI am also looking for news on this. Any progress?
Comment #25
Christopher Riley CreditAttribution: Christopher Riley commentedIs this a feature that we can just not look forward to having or is it possible to get it functional?
Comment #26
joel_osc CreditAttribution: joel_osc at OpenPlus commentedIs there anyone looking into this for 8.7? IMHO this is quite an important piece of functionality.
Comment #27
manuel.adanI'm with you that it is a really required feature. I trying to convince my boss of spending more time in contrib, but no case by now ;)
In the mean time, menu links can be added in a custom module as follows:
"your_module.links.menu.yml":
Drupal Console can be used to get a list of the available page manager pages in your system:
$ console debug:router | grep "page_manager.page"
Comment #28
joel_osc CreditAttribution: joel_osc at OpenPlus commentedThanks @manuel.adan! I was just looking into how to do this. Appreciate the help.
Comment #29
joel_osc CreditAttribution: joel_osc at OpenPlus commentedActually, my menu requirements are a bit different as I am trying to add a tabs (menu local tasks) to a node view (example /node/43/my-tab). Any advice is appreciated.
Comment #30
joel_osc CreditAttribution: joel_osc at OpenPlus commentedIf anyone else runs into this, you need to create a dynamic local task... I used entity_clone as an example and then trimmer it down to what I needed. I would recommend reading this: https://www.drupal.org/docs/8/api/menu-api/providing-module-defined-loca... and then create a mymodule.links.task.yml file to generate the local tasks in the derivative class placed at src/Plugin/Derivative/DynamicLocalTasks.php as follows:
And then create the deriver something like as follows:
Comment #31
geek-merlinPatch flying in with a brain-dead reroll of #18. I'm quite impressed that this is even possible after 6 years. Let's see what breaks.
TODO: Port the simpletests from #18.
Comment #33
geek-merlinMissed some API runaways.
Comment #34
geek-merlinComment #35
andypostNice to see this resurrected)
Comment #36
geek-merlinI tested this locally and besides showing the config form it's not yet useful. So NW.
Comment #37
andypostComment #38
dsnopekI'm closing this one as a duplicate of #2620036: Allow pages to have menu items.
That issue also provides support for local tasks and actions (in addition to normal menu items), and it has an up-to-date, working patch.
Looking at the latest patch on this issue, there are some small features here than aren't implemented there, for example, setting additional visibility paths on local actions. However, I think it'd be easier to add those into the patch on the other issue (or in a follow-up) rather than trying to resurrect this one.