Support from Acquia helps fund testing for Drupal Acquia logo

Comments

larowlan created an issue. See original summary.

larowlan’s picture

Status: Active » Needs review
FileSize
1.25 KB

I might be making this up

Wim Leers’s picture

Issue tags: +Routing

So: you're saying that handle() should have RestResourceConfigInterface $rest_resource_config as one of its parameters, and then the routing system should do the upcasting automatically. Correct?

EDIT: cross-posted — looks like that is what @larowlan meant.

Wim Leers’s picture

Oh, even without the upcasting!

larowlan’s picture

+++ b/core/modules/rest/src/RequestHandler.php
@@ -80,14 +80,15 @@ public static function create(ContainerInterface $container) {
+   * @param string $_rest_resource_config
...
+  public function handle(RouteMatchInterface $route_match, Request $request, $_rest_resource_config) {
...
+    $resource_config = $this->resourceStorage->load($_rest_resource_config);

We might need a named slug for this to work, we'll see. Could be dreaming this up.

If it works, would be interested to see if we could make it use the entity converter too by setting the needed options, then we can avoid the ::load

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

Love the thinking, doubt it works, would love to be wrong, will check in the morning!

Status: Needs review » Needs work

The last submitted patch, 2: resource-handle-args-2935783.patch, failed testing. View results

larowlan’s picture

Status: Needs work » Needs review
FileSize
1.49 KB
2.73 KB

so it works, next step, adding the entity type options and making it use the actual config entity

Wim Leers’s picture

Woahhhhh! TIL. 👌

Wim Leers’s picture

Assigned: Wim Leers » jhedstrom
Status: Needs review » Reviewed & tested by the community
FileSize
751 bytes
2.74 KB

Only fixed a docs nit.

So this doesn't do upcasting, but it does mean there's no more need to inspect the route match's matched route object just to read a route default. Still a win :) One LoC less!

Wim Leers’s picture

Assigned: jhedstrom » Unassigned

Oops.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
4.16 KB
5.67 KB

i think we can do better, will need to update the kernel test still (doesn't include #10 yet)

Status: Needs review » Needs work

The last submitted patch, 12: resource-handle-args-2935783-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Wim Leers’s picture

#12 is what I thought you originally meant, and what I thought that couldn't work.

Looks like it doesn't. 100% of REST integration tests fail with:

Exception: TypeError: Argument 3 passed to Drupal\rest\RequestHandler::handle() must be an instance of Drupal\rest\RestResourceConfigInterface, string given
Drupal\rest\RequestHandler->handle()() (Line: 78)
larowlan’s picture

Status: Needs work » Needs review
FileSize
3.2 KB
6.61 KB

Messed up #12

larowlan’s picture

+++ b/core/modules/rest/src/Routing/ResourceRoutes.php
@@ -128,7 +128,7 @@ protected function getRoutesForResourceConfig(RestResourceConfigInterface $rest_
-            'type' => $rest_resource_config->getEntityTypeId(),
+            'type' => 'entity:' . $rest_resource_config->getEntityTypeId(),

this was my mistake

Status: Needs review » Needs work

The last submitted patch, 15: resource-handle-args-2935783.4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

larowlan’s picture

Status: Needs work » Needs review
FileSize
872 bytes
6.65 KB

winning

larowlan’s picture

sweet

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
785 bytes
6.65 KB

Very happy to be wrong! 😀

And great to have an example in core of how to get a route default to be upcasted!

Only bringing back my nitpick fixes from #10, then this is RTBC.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 2935783-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

larowlan’s picture

Status: Needs work » Reviewed & tested by the community

l.d.o http transfer issues

Wim Leers’s picture

Indeed! Retesting…

catch’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Fixed

Just saw this yesterday and thought it looked a bit clunky, then saw this issue today.

Committed/pushed to 8.6.x and cherry-picked to 8.5.x. Thanks!

  • catch committed 096ecb4 on 8.6.x
    Issue #2935783 by larowlan, Wim Leers: RequestHandler's handle method...

  • catch committed a8b80d8 on 8.5.x
    Issue #2935783 by larowlan, Wim Leers: RequestHandler's handle method...
catch’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.