#3004582: Make JSON API Extras 2.x (next release: 2.10) compatible with JSON API 2.0-beta2 will introduce the following check:

+++ b/src/ResourceType/ConfigurableResourceTypeRepository.php
@@ -71,28 +63,60 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
+   * One of the BC breaks in 2.x is the removal of JSON API 1.x's custom
+   * computed "url" field to File entities. Hence its presence or absence is
+   * also a very reliable detection mechanism.
...
+  public static function isJsonApi2x() {
+    return !class_exists('\Drupal\jsonapi\Field\FileDownloadUrl');
+  }

This is robust while JSON API remains in contrib, but once JSON API is in core. It's possible that both 1.x and 2.x will be present in a Drupal codebase. Even though we're sure that the contrib version is the one which is used, I'm not sure if PHP knows not to load the core classes when the module is unused. Let's ensure that this will be correct in that case.

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

wim leers’s picture

Impressive edge case that you thought of!

I think JSON API being in core can be detected quite simply though: file_exists('core/modules/jsonapi') :)

e0ipso’s picture

Status: Active » Closed (won't fix)

While I think it was worth the effort, I think that it makes sense for my sanity to start sunsetting JSON:API 1.x and its support here in JSON:API Extras.

JSON:API Extras 3.x will only support JSON:API 2.x.