- Issue created by @vasyapledov
- Status changed to Needs work
4 months ago 3:04pm 11 July 2024 The Needs Review Queue Bot → tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request → . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
- Status changed to Needs review
4 months ago 7:24pm 11 July 2024 - Status changed to Needs work
4 months ago 8:05pm 11 July 2024 vasyapledov → changed the visibility of the branch 3460831-alter-route-callback to hidden.
vasyapledov → changed the visibility of the branch 3460831-alter-route-callback to active.
vasyapledov → changed the visibility of the branch 11.x to hidden.
vasyapledov → changed the visibility of the branch 11.x to active.
- Merge request !8863Issue #3460831 by vasyapledov: Add alter for `route_callbacks` → (Open) created by vasyapledov
vasyapledov → changed the visibility of the branch 3460831-alter-route-callback to hidden.
vasyapledov → changed the visibility of the branch 3460831-alter-route-callback to active.
- Status changed to Needs review
4 months ago 3:49pm 21 July 2024 - Status changed to Needs work
4 months ago 2:28pm 23 July 2024 The Needs Review Queue Bot → tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.
- Status changed to Needs review
4 months ago 1:03pm 25 July 2024 - Status changed to Needs work
4 months ago 1:27pm 25 July 2024 The Needs Review Queue Bot → tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide → to find step-by-step guides for working with issues.
- 🇮🇳India arunkumark Coimbatore
@vasyapledov
Am have a different opinion on the feature you are proposing about altering the routing effortlessly. We already have the option to alter any existing route via the EventSubscribers. The protected method alterRoutes() will give the ability to alter all routing parameters. The documentation is available here → .
The effort to create the MODULE.routing.alter.yml and implement EventSubscribers are more or less the same. Let's get opinions from others about the feature.
Your Merge Request and Patch are not applied to the Drupal core 11.x. The message from needs-review-queue-bot automatically adds if the patch fails to apply. In this case, you have to rebase and create the MR or Patch. Already you created the MR, better to go with MR hereafter.
References:
[1] https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr... →
[2] https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing... → - Status changed to Needs review
4 months ago 7:06am 26 July 2024 @arunkumark
If you can give me a better implementation - I will be very grateful.
I made this solution because I found no other options.jsonapi.routing.yml
route_callbacks: - '\Drupal\jsonapi\Routing\Routes::routes'
Explain me, please, how to alter
route_callback
for jsonapi without call'\Drupal\jsonapi\Routing\Routes::routes'
According with
\Drupal\Core\Routing\RouteBuilder::rebuild
Not from documentation (I know it) - check real code please.$callback = $this->controllerResolver->getControllerFromDefinition($route_callback); if ($callback_routes = call_user_func($callback)) {
- Status changed to Active
4 months ago 7:21am 26 July 2024 - Status changed to Needs review
4 months ago 7:31am 26 July 2024 Strange.
The patch is applied successfully at my place locally on several Drupal variants.Gathering patches for dependencies. This might take a minute. - Installing drupal/core (11.0.0-rc1): Extracting archive - Applying patches for drupal/core https://git.drupalcode.org/project/drupal/-/merge_requests/8863.diff (Add alter for `route_callbacks`)
- 🇮🇳India arunkumark Coimbatore
@vasyapledov
Please read the documentation of using
RoutingEvents::ALTER
andRoutingEvents::DYNAMIC
fromDrupal\Core\Routing\RouteBuilder.php
// DYNAMIC is supposed to be used to add new routes based upon all the // static defined ones. $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::DYNAMIC); // ALTER is the final step to alter all the existing routes. We cannot stop // people from adding new routes here, but we define two separate steps to // make it clear. $this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::ALTER);
The core RESTful module used RoutingEvents::DYNAMIC to build and manage the dynamic route.
@arunkumark
Please read the documentation of using RoutingEvents::ALTER and RoutingEvents::DYNAMIC from Drupal\Core\Routing\RouteBuilder.php
This code works AFTER
route_callback
.
Removing the execution results of the oldroute_callback
is not a good idea, in my opinion.
It's much easier and better to use the new call instead of the old one - it's faster, easier and more reliable.You didn't answer to my question, sorry.
I'll rephrase the question.How to prevent execution of existing
route_callback
call?
How to execute another function only? I don't need existing totally - I need a new one.- Status changed to Needs work
3 months ago 2:49pm 11 August 2024 - 🇺🇸United States smustgrave
Checking the MR believe a change like that will definitely need test coverage.
- Status changed to Needs review
3 months ago 10:15am 22 August 2024 - Status changed to Needs work
3 months ago 2:40pm 29 August 2024 - 🇺🇸United States smustgrave
Briefly scanned the MR few things I noticed
New functions are missing return typehints
Changes to test script should be reverted
todo's in the comments, either should be resolved or have a issue linked in them.