Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mkolar created an issue. See original summary.

e0ipso’s picture

This is exciting! 👏🏽

mkolar’s picture

Hi :).. here is first try.. Its a plain submodule so no code changes in defaults or extras. I'll test this tomorrow probably. And Im not sure now about update hook if it should stay or not, Im not sure about workflow moving from standalone to submodule now (not sure if you need to uninstall standalone defaults first, than update extras and than enable it, than update hook is not needed).

e0ipso’s picture

I'll test this tomorrow probably.

Great! Let me know when you're done with your testing. I'll add my review then.

yobottehg’s picture

I gave this a testrun and it works great.

I would suppose to add the following:

  • On an article node. If i default include a field_media and on the the media i default include the field_image i expect to have field_media.field_image on the includes if i query the node
  • this would also help tremendously with other includes like paragraphs and dynamic entity references like media (image or video for example)

This would help to get rid of default_includes like the following:

field_author
field_author.field_image
field_author.field_image.field_image
field_category
field_content
field_content.field_image
field_content.field_image.field_image
field_hero_image
field_hero_image.field_image

because this would be enough:

field_author
field_category
field_content
field_hero_image

Here a little bit more elaboration why i think this would be a great next step and some more possible improvments

  • Until now we did not know if the included entity has other includes. Now we do and we should use this knowledge
  • I would not use a submodule for this but just add this as a normal feature
  • I think we should attach a checkbox to all reference fields on the overwrites page instead of having a default includes text field
  • Filters will probably need to live in the textarea as they will be much more complicated to include for each field.
e0ipso’s picture

I made several adjustments to bring it up to speed to the latest available APIs. I also took the liberty to change the format slightly (see screenshot). On top of that I created some automated tests to make sure everything works as expected.

Finally, before we commit this we should turn those TODO items into drupal.org issues. In addition to that we'll need to have an issue to use service decoration instead of service swapping in jsonapi_defaults.


Please let me know about this.

Status: Needs review » Needs work

The last submitted patch, 6: 2997956--integrate-jsonapi-defaults--6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

e0ipso’s picture

For some reason this is creating test patch failures for JSON API Extras. We'll need to figure this out before merging.

@mkolar I am not actively working on this anymore, will you take over bringing this to the finish line?

mkolar’s picture

Hi, sorry for being away a while.. I was ill and lot of work to do in my regular job, can’t promise anything now. But will try to investigate why tests are failing.

mkolar’s picture

Regarding what @yobottehg wrote. Not sure it’s good idea to automatically include entities as suggested because sometimes you don’t want to expose something from included reference for example role from author.. but would be good that writing this “field_author.field_image.field_image” would be enough so no need to write all three lines for this entity. Also this is not good point for implement any new feature so let’s create new ticket as soon as this merge is done and discuss there.

Wim Leers’s picture

Would this go into a new 8.x-3.x branch?

e0ipso’s picture

@Wim Leers I'm not sure about that. I didn't really think about it. Any reason to require a major version change?

e0ipso’s picture

Status: Needs work » Needs review
FileSize
29.85 KB

Re-roll

Status: Needs review » Needs work

The last submitted patch, 13: 2997956--integrate-jsonapi-defaults--13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

e0ipso’s picture

Related issues: +#3012991: JSON:API Defaults
ndobromirov’s picture

Will be able to push a bit in here in the next few days.

e0ipso’s picture

That's fantastic news @ndobromirov!

rhristov’s picture

Status: Needs work » Needs review
FileSize
31.17 KB

I have created a new patch that is compliant with JSON API 2.

Since the JSON API doesn't allow other modules to define normalizers I have created a new controller that overrides the one defined in JSON API. From this controller, I have added a method that overrides the one from JSON API which injects the includes.

Status: Needs review » Needs work

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

rhristov’s picture

Applying a new patch and interdiff with the previous one, that I will hide.

There was an issue with the patch that I used as a starting point from #13 - when saving the include configurations they were not split per line.

Wim Leers’s picture

@e0ipso: do you plan to add this to JSON API Extras 8.x-2.x or 8.x-3.x?

ndobromirov’s picture

I would consider this 2.x material, as it's an pure API addition. 3.x was added as a means to start clearing backwards compatibility overhead.
On top of that what's the update path for people in contrib that are still using jsonapi_defaults?

jsonapi_defaults works with jsonapi 1.x and jsonapi_extras 2.x (almost). Unless there is jsonapi_defaults in the 2.x extras, there is no way people can reach 3.x safely and incrementally (1 -> 2 -> 3).

Wim Leers’s picture

Issue tags: +API-First Initiative

On top of that what's the update path for people in contrib that are still using jsonapi_defaults?

jsonapi_defaults works with jsonapi 1.x and jsonapi_extras 2.x (almost). Unless there is jsonapi_defaults in the 2.x extras, there is no way people can reach 3.x safely and incrementally (1 -> 2 -> 3).

Excellent point!

rhristov’s picture

Status: Needs work » Needs review
FileSize
29.44 KB
2.24 KB

I have created a new patch based on #20.

The difference is that we are changing the way we alter the JSONAPI controller to inject the includes: previously we were relying on route subscriber and now we are overriding the controller defined as a service.

Applying an interdiff with the changes from the previous patch.

rhristov’s picture

Status: Needs review » Needs work

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

ndobromirov’s picture

Patch does not apply against latest dev :(.
@Rosen, can you try resolving the problematic tests as well?

rhristov’s picture

Applying a new patch created from #20.

Changes:
Added a dependency on jsonapi_defaults submodule to jsonapi v2.
Fixed coding standard issues.

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

rhristov’s picture

The tests are failing, but it is not related to the applied patch.

When executed against the latest dev version they are failing with same output.

I will try to resolve the tests, but I will appreciate if someone gets involved too.

As a hint, I saw that when the tests are running the \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository::isJsonApi2x returns TRUE no matter that it tests against JSONAPI v1.

e0ipso’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev

Let's try against 8.x-3.x.

e0ipso’s picture

rhristov’s picture

@e0ipso see this comment here: https://www.drupal.org/project/jsonapi_extras/issues/3017255#comment-128... , once merged we could retest the latest patch.

e0ipso’s picture

Let's see if we can apply against 3.x instead.

Status: Needs review » Needs work

The last submitted patch, 34: 2997956--integrate-jsonapi-defaults--34.patch, failed testing. View results

e0ipso’s picture

Assigned: mkolar » Unassigned

@rhristov it seems we are a bit closer on this. Can you take a look at the failing test and do some manual testing of your own?

I had to remove you from the composer.json since we only list there the original authors of the modules. That was part of the agreement in #2985845: Join efforts: Consider merging with JSON API Extras. I hope you understand. Your contribution is really valued! and credit will be granted on commit.

e0ipso’s picture

Alright, let's see if now we are good!

e0ipso’s picture

Status: Needs work » Needs review
e0ipso’s picture

Great! Tests are green. Can someone else test this patch manually before committing?

ndobromirov’s picture

Will add it to our builds some time today and ping back.

e0ipso’s picture

Will add it to our builds some time today and ping back.

Awesome! Thanks for that.

mkolar’s picture

Hello guys, thanks for the work. Since i didn't have time to finish this I've just spent some time testing it in my projects at least... and looks like it all works as before after some configuration!

installed version
"name": "drupal/core",
"version": "8.6.3",

"name": "drupal/jsonapi",
"version": "2.0.0-rc2",

"name": "drupal/jsonapi_extras",
"version": "3.0.0-rc3",

+ patch https://www.drupal.org/files/issues/2018-12-06/2997956--integrate-jsonap...

e0ipso’s picture

  • e0ipso committed 0e7ca57 on 8.x-3.x authored by mkolar
    Issue #2997956 by e0ipso, rhristov, mkolar, ndobromirov, Wim Leers,...
  • e0ipso committed bb5bd21 on 8.x-3.x authored by rhristov
    Issue #2997956 by e0ipso, rhristov, mkolar, ndobromirov, Wim Leers,...
  • e0ipso committed d536d80 on 8.x-3.x
    Issue #2997956 by e0ipso, rhristov, mkolar, Wim Leers, ndobromirov,...
e0ipso’s picture

Status: Needs review » Fixed

Great work everyone!

@mkolar, can you mark JSON API Defauluts as deprecated in the module page and point people here to JSON API Extras?

mkolar’s picture

@e0ipso I already did that day you committed it here.

Status: Fixed » Closed (fixed)

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