Problem/Motivation

#2793809: [FEATURE] Provide direct download URLs for files and images introduced this, because JSON API couldn't wait for core to fix it — it's been in progress for years.

Proposed resolution

Once #2825487: Fix normalization of File entities: file entities should expose the file URL as a computed property on the 'uri' base field finally lands, we'll be able to remove JSON API's work-around.

But, we'll need to retain BC. Existing sites should continue to get the JSON API's addition. New sites should only offer what core provides.

Remaining tasks

None.

User interface changes

None.

API changes

The responses for /jsonapi/file will change. JSON API clients can gently migrate from JSON API 1.x to 2.x. See the CR for details: https://www.drupal.org/node/2982209.

Data model changes

None. (Well, no longer modifying the File entity type data model!)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Status: Active » Needs review
Issue tags: -API-First Initiative +Needs update path tests
FileSize
2.29 KB

Something like this.

Wim Leers’s picture

Status: Needs review » Postponed
Wim Leers’s picture

Wim Leers’s picture

Title: [PP-1] Remove JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » [PP-1] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it
Issue tags: +Needs tests

Title was inaccurate.

Also needs BC tests.

e0ipso’s picture

@Wim Leers we need a plan to incorporate core fixes while deprecating jsonapi workarounds. We are about to drop D8.2 (I've made my mind finally) but we can't reliably depend on fixes that *just* happened.

I'd like to hear your thoughts on how to maintain all the balls in the air: sites that were using the workaround that need to transition to the core feature, sites that are not running a core version with the fix, sites that run a modern version of core along with an old version of jsonapi, etc.

My gut tells me this is going to be tricky… I think. Or maybe not, I haven't thought about it in depth yet.

Wim Leers’s picture

Wim Leers’s picture

Title: [PP-1] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » [PP-2] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it

If possible, #2921257: On Drupal 8.5, JSON API should respect Typed Data's new ::isInternal(), and JSON API Extras should use ::setInternal() should land first, and then this should take care of BC/update path concerns.

Updating to PP-2, because #2921257 is PP-1.

garphy’s picture

FileSize
1.7 KB

A rebase was needed.

garphy’s picture

FileSize
1.71 KB
495 bytes

Access to the retrieved ImmutableConfig instance was incorrect.

garphy’s picture

FileSize
2.66 KB
980 bytes

Use TypedDataInternalPropertiesHelper::getNonInternalProperties() to extract non-internal properties in FieldItemNormalizer.

Otherwise, new computed url is never included in serialized output.

Wim Leers’s picture

#11: yep, the extra step you've taken there is a hard blocker for this issue. And for that, we have a separate issue: #2921257.

Would you like to help out with that? :) Initial patch at #2921257-10: On Drupal 8.5, JSON API should respect Typed Data's new ::isInternal(), and JSON API Extras should use ::setInternal(), which includes your interdiff in #11, plus one extra necessary change. Would be great to get to a green patch there!

Wim Leers’s picture

Title: [PP-2] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » [PP-1] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it
Wim Leers’s picture

Title: [PP-1] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it
Status: Postponed » Needs review
Issue tags: -Needs tests
FileSize
6.01 KB
6.37 KB
Wim Leers’s picture

  1. +++ b/jsonapi.install
    @@ -0,0 +1,35 @@
    +function jsonapi_install() {
    +  // For new sites, also still enable JSON API's custom base field, if it's a
    +  // new site starting on Drupal <8.5. Because only in Drupal >=8.5, core ships
    +  // with an alternative.
    +  // @todo Remove this when JSON API requires Drupal 8.5.
    +  if (floatval(\Drupal::VERSION) < 8.5) {
    

    This ensures that new sites starting to use JSON API will get the BC layer if they use Drupal 8.4 or older, and will not get the BC layer of they use Drupal 8.5 or newer.

  2. +++ b/jsonapi.install
    @@ -0,0 +1,35 @@
    +function jsonapi_update_8101() {
    

    This ensures all existing sites using JSON API continue to behave exactly the same.

Status: Needs review » Needs work

The last submitted patch, 15: 2926463-15.patch, failed testing. View results

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
958 bytes
6.27 KB

I wrote #16 to explain the patch, and in doing so, I found a mistake in a part I also wanted to leave a comment for.

Status: Needs review » Needs work

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

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
1.92 KB
7.45 KB
Wim Leers’s picture

Status: Needs review » Needs work

The last submitted patch, 20: 2926463-20.patch, failed testing. View results

e0ipso’s picture

WRT the interdiff in #20 I would really rather avoid the bc_* configuration objects. That was a measure to avoid a new major version bump in Drupal core (because rest versions are coupled to core's versions).

In this case I want us to take one of the two options:

  1. Create a new major release and drop legacy code.
  2. Support both URLs. When the legacy one is rendered, we could use Partial Success to add a deprecated notice that instructs to use the other field.

Which one do you prefer?

Wim Leers’s picture

Assigned: Unassigned » e0ipso

Ah, darn, I wish you'd said that in a previous comment … oh well, that happens :)

We need to give people time to update, so your second suggestion is the only one that can really work.

I'm not sure how exactly you envision that would work, so assigning to you.

e0ipso’s picture

I'm so sorry @Wim Leers. How do you feel about it? I'm not set in stone about this.

Wim Leers’s picture

Sorry, hadn't seen #25 until now!

I would love to not have to deal with BC configuration. But that's the right thing to do to ease the transition.

  1. Creating a new major release and dropping the legacy code is a way to not have to deal with BC. It would also mean we could require Drupal 8.5 as the minimum version, which also would allow us to remove lots existing version-dependent logic (and especially tests). Plus, it'd make it easier to move JSON API into core. So … that sounds wonderful! :)
  2. Supporting both URLs is exactly what #20 does, but with a BC config flag so that only existing sites/sites already in development can continue to work without making any changes. New sites would only get the "proper" behavior.

    The approach you propose would also allow new sites to use the old behavior. The deprecation notice in meta would be easily missed. I don't understand how you could use Partial Success for this, can you explain that?

I'd love to do #1, but it does force JSON API users to adjust their consumer code. If we can live with that, then sure, yes, that sounds great!

Wim Leers’s picture

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

I have the impression that @e0ipso wants to branch version 2 and remove this in there? Tentatively moving to that branch and awaiting his feedback.

Wim Leers’s picture

Title: Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » [>=8.5] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it
e0ipso’s picture

Assigned: e0ipso » Unassigned

Yeah, let's move this to the new major now that we have a plan for it. Let's embrace semver!

Wim Leers’s picture

Title: [>=8.5] Deprecate JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it » [>=8.5] Remove JSON API's "file URL" field work-around now that Drupal core 8.5 fixed it
Status: Needs work » Needs review
Issue tags: -Needs update path tests +Needs change record
FileSize
6.29 KB

The 2.x branch is about to start … 🚀

So, time to reroll this patch! I'm very grateful to @e0ipso for insisting to not add a BC layer and instead only drop this in the next version of the JSON API module. Because it makes this an order of magnitude simpler!

Status: Needs review » Needs work

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

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
1.58 KB
7.66 KB

I missed two details :)

Wim Leers’s picture

CR created: https://www.drupal.org/node/2982209.

IS updated.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Green patch, simple patch, epic diffstat (5 files changed, 1 insertions, 185 deletions), based on consensus with @e0ipso. What's not to like? :)

The last submitted patch, 11: 2926463-11.patch, failed testing. View results

  • gabesullice committed 1c9544e on 8.x-2.x
    Issue #2926463 by Wim Leers, garphy, e0ipso: [>=8.5] Remove JSON API's "...
gabesullice’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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