Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

Issue summary: View changes

Fixed issue link in summary

gabesullice’s picture

Assigned: Unassigned » gabesullice
StatusFileSize
new11.37 KB

Let's get this going.

First, let's point all the routes away from the request handler and directly at the appropriate EntityResource methods.

gabesullice’s picture

StatusFileSize
new3.11 KB
new14.29 KB

Now we can remove the RequestHandler class completely.

gabesullice’s picture

StatusFileSize
new9.05 KB
new23.35 KB

For the same reason that we renamed the parameter from 'node' to 'entity' (i.e. so that the arguments resolver would work) in #2987609: Rename the entity parameter from the entity type ID to 'entity' for all routes, we need to rename the $related_field parameter to $related because that's what our route definitions declare.

gabesullice’s picture

Assigned: gabesullice » Unassigned
Status: Active » Needs review
StatusFileSize
new7.32 KB
new87.96 KB
new30.67 KB

Finally, let's make update Unit\RoutesTest.php

Status: Needs review » Needs work

The last submitted patch, 6: 2987610-6.patch, failed testing. View results

gabesullice’s picture

Title: Remove RequestHandler class and service and add EntityResource methods to each route definition » [PP-1] Remove RequestHandler class and service and add EntityResource methods to each route definition
Status: Needs work » Postponed
StatusFileSize
new89.3 KB
new32.19 KB
gabesullice’s picture

StatusFileSize
new19.49 KB
new88.03 KB
new2.55 KB

I included a commit that I intend to make a follow up for.

wim leers’s picture

StatusFileSize
new30.67 KB

The 2987610-9.patch patch was incorrect. I solved it by applying 2987610-9.patch and then reverting interdiff-removed-from-patch.txt.

Intended patch attached.

wim leers’s picture

StatusFileSize
new745 bytes

Fix for #9's failure.

wim leers’s picture

  1. +++ b/jsonapi.services.yml
    @@ -146,13 +146,8 @@ services:
       # Controllers.
    -  jsonapi.request_handler:
    -    class: \Drupal\jsonapi\Controller\RequestHandler
    -    arguments:
    -      - '@jsonapi.entity_resource'
       jsonapi.entity_resource:
         class: \Drupal\jsonapi\Controller\EntityResource
    -    public: false
    

    🚀😍

  2. +++ b/src/Controller/EntityResource.php
    @@ -408,15 +408,15 @@ class EntityResource {
    -   * @param string $related_field
    +   * @param string $related
    

    This is to allow Drupal's routing system to handle this for us, right?

    Question: why change these signatures if we could also just update this in Routes:
    $relationship_route->addDefaults(['related' => $relationship_field_name]);
    to
    $relationship_route->addDefaults(['related_field' => $relationship_field_name]);

    That'd make this patch much smaller.

  3. +++ b/src/Controller/EntityResource.php
    @@ -688,13 +688,13 @@ class EntityResource {
    diff --git a/src/Controller/RequestHandler.php b/src/Controller/RequestHandler.php
    
    diff --git a/src/Controller/RequestHandler.php b/src/Controller/RequestHandler.php
    deleted file mode 100644
    

    👏

  4. +++ b/src/Routing/Routes.php
    @@ -29,7 +29,7 @@ class Routes implements ContainerInjectionInterface {
    -  const FRONT_CONTROLLER = 'jsonapi.request_handler:handle';
    +  const FRONT_CONTROLLER = 'jsonapi.entity_resource';
    

    It's no longer a front controller. It's just a controller. (Albeit the only one, at least for now.)

    I'd either rename this to CONTROLLER, or … get rid of it altogether, and just write

    RouteObjectInterface::CONTROLLER_NAME =>
     'jsonapi.entity_resource:getCollection'

    , for example.

  5. +++ b/src/Routing/Routes.php
    @@ -232,16 +236,24 @@ class Routes implements ContainerInjectionInterface {
    +        'GET' =>    'getRelationship',
    +        'POST' =>   'createRelationship',
    +        'PATCH' =>  'patchRelationship',
    +        'DELETE' => 'deleteRelationship',
    

    Übernit: I <3 this whitespace, but Drupal core does not allow it.

  6. +++ b/src/Routing/Routes.php
    @@ -232,16 +236,24 @@ class Routes implements ContainerInjectionInterface {
    +      foreach ($relationship_route_methods as $method) {
    +        $method_specific_relationship_route = clone $relationship_route;
    +        $method_specific_relationship_route->addDefaults([RouteObjectInterface::CONTROLLER_NAME => static::FRONT_CONTROLLER . ":{$relationship_controller_methods[$method]}"]);
    +        $method_specific_relationship_route->setMethods($method);
    +        $routes->add(static::getRouteName($resource_type, sprintf("%s.relationship.%s", $relationship_field_name, strtolower($method))), $method_specific_relationship_route);
    +      }
    

    🤘

  7. +++ b/tests/src/Unit/Routing/RoutesTest.php
    @@ -71,11 +71,11 @@ class RoutesTest extends UnitTestCase {
    +    // - 12 routes; 3 fields * 4 HTTP methods.
    

    Nit: s/12 routes/12 relationship routes/

gabesullice’s picture

Title: [PP-1] Remove RequestHandler class and service and add EntityResource methods to each route definition » Remove RequestHandler class and service and add EntityResource methods to each route definition
Status: Postponed » Active
gabesullice’s picture

Title: Remove RequestHandler class and service and add EntityResource methods to each route definition » [PP-1] Remove RequestHandler class and service and add EntityResource methods to each route definition
Status: Active » Postponed
gabesullice’s picture

gabesullice’s picture

Status: Postponed » Needs review
StatusFileSize
new36.14 KB
new59.06 KB

Rerolled to be applied after #2987608: Move deserialization from RequestHandler to JsonApiParamEnhancer.


#12

  1. 🤘
  2. Unfortunately it wouldn't make the patch much smaller, because we'd then need to change ever place that Url::fromRoute is called with 'related' to 'related_field'. The parameter has always be related, it's the controller that was using different naming since naming didn't matter.
  3. 🤘
  4. Gonna change it to CONTROLLER_SERVICE_NAME, I think that's most accurate. I like having the constant vs. a string.
  5. Will do.
  6. 🤘
  7. Will do.
gabesullice’s picture

StatusFileSize
new36.86 KB
new13.32 KB
new59.77 KB

4 + 5 + 7 + some other clean ups.

For example, we need to name $entity to $parsed_entity so the name is the same for createIndividual and patchIndividual

The last submitted patch, 16: 2987610-16.patch, failed testing. View results

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

The last submitted patch, 17: 2987610-17.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 17: 2987610-17.combined.patch, failed testing. View results

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new37.5 KB
new60.42 KB

Fixes the CS violation. I also forgot one route name change which caused the test failure.

The last submitted patch, 22: 2987610-22.patch, failed testing. View results

gabesullice’s picture

StatusFileSize
new37.69 KB
new60.6 KB

Reroll.

The last submitted patch, 24: 2987610-24.patch, failed testing. View results

wim leers’s picture

Status: Needs review » Postponed

#16.2: Ahh, that makes sense. Too bad 😞

No further remarks. RTBC when the blocker lands!

For now, marking postponed.

gabesullice’s picture

StatusFileSize
new37.62 KB
new60.55 KB

Rerolled.

wim leers’s picture

Rebased #27 on top of not only #2987608: Move deserialization from RequestHandler to JsonApiParamEnhancer but also #2958554: Allow creation of file entities from binary data via JSON API requests, because #2958554 changes some things in EntityResource that conflict with some of the changes here. This is just for testing purposes in #2958554.

wim leers’s picture

Title: [PP-1] Remove RequestHandler class and service and add EntityResource methods to each route definition » Remove RequestHandler class and service and add EntityResource methods to each route definition
Status: Postponed » Needs work

#2987608: Move deserialization from RequestHandler to JsonApiParamEnhancer just landed!

Needs work because of #27's failures.

gabesullice’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB
new39.66 KB

It looks like a few $related_field -> $related changes got missed in the reroll (see #5 and #16.2 for a reminder about why those changes are necessary).

gabesullice’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC per #26

The last submitted patch, 3: 2987610-3.patch, failed testing. View results

The last submitted patch, 4: 2987610-4.patch, failed testing. View results

The last submitted patch, 5: 2987610-5.patch, failed testing. View results

The last submitted patch, 9: 2987610-9.patch, failed testing. View results

The last submitted patch, 8: 2987610-8.patch, failed testing. View results

The last submitted patch, 27: 2987610-27.patch, failed testing. View results

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

👌

P.S.: I love the smell of a lovely diffstat in the morning: 11 files changed, 97 insertions(+), 184 deletions(-) 😍

  • Wim Leers committed 9abbe04 on 8.x-2.x authored by gabesullice
    Issue #2987610 by gabesullice, Wim Leers: Remove RequestHandler class...
wim leers’s picture

Status: Fixed » Active

d.o is again suffering from a race condition; in some places this is marked as Fixed, in others it's marked as RTBC. Let's fix that changing the status twice.

wim leers’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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