summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authore0ipso2018-12-05 23:38:28 (GMT)
committerMateu Aguiló Bosch2018-12-05 23:38:28 (GMT)
commit39f1e14a22c7e6a794555b7dc5209945df09a665 (patch)
tree040abc1068749e30bff2645459646e745dadbb36
parent1ff3e206962678977c0230dc639a50f68e43df85 (diff)
Issue #3017255 by ndobromirov, rhristov, e0ipso: Add a static cache on the isJsonApi2x() method8.x-2.148.x-2.x
-rw-r--r--src/ResourceType/ConfigurableResourceTypeRepository.php22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/ResourceType/ConfigurableResourceTypeRepository.php b/src/ResourceType/ConfigurableResourceTypeRepository.php
index c377969..8baf8e6 100644
--- a/src/ResourceType/ConfigurableResourceTypeRepository.php
+++ b/src/ResourceType/ConfigurableResourceTypeRepository.php
@@ -73,15 +73,23 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
* @todo Remove this when JSON API Extras drops support for JSON API 1.x.
*/
public static function isJsonApi2x() {
- static $result = NULL;
+ static $is_2x = NULL;
- if ($result === NULL) {
- $v = ModuleHandler::parseDependency('jsonapi(>= 8.x-2.0-beta1)');
- $module_list = \Drupal::service('extension.list.module')->getList();
- $result = NULL === drupal_check_incompatibility($v, $module_list['jsonapi']->info['version']);
+ if ($is_2x !== NULL) {
+ return $is_2x;
}
-
- return $result;
+ $extension = \Drupal::service('extension.list.module')->get('jsonapi');
+ $version = $extension->info['version'];
+ if ($version === NULL) {
+ // When running a git clone of the module we will not get a version number
+ // here. In this case we resort to checking for a 2.x only service.
+ $is_2x = \Drupal::hasService('jsonapi.include_resolver');
+ }
+ else {
+ $dependency = ModuleHandler::parseDependency('jsonapi(>= 8.x-2.0-beta1)');
+ $is_2x = drupal_check_incompatibility($dependency, $version) === NULL;
+ }
+ return $is_2x;
}
/**