Unverified Commit 39f1e14a authored by e0ipso's avatar e0ipso Committed by Mateu Aguiló Bosch

Issue #3017255 by ndobromirov, rhristov, e0ipso: Add a static cache on the isJsonApi2x() method

parent 1ff3e206
......@@ -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;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment