From 77cf0e3efc733696c4deffbc1e8ee6359572cb4c Mon Sep 17 00:00:00 2001
From: ndobromirov <ndobromirov@2451988.no-reply.drupal.org>
Date: Tue, 13 Aug 2019 23:04:52 +0200
Subject: [PATCH] Issue #3019729 by ndobromirov, Wim Leers, rhristov, e0ipso:
 Invalidate JSON:API Extras' cache tags when needed

---
 .../ConfigurableResourceTypeRepository.php    | 34 ++++++++++++++-----
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/ResourceType/ConfigurableResourceTypeRepository.php b/src/ResourceType/ConfigurableResourceTypeRepository.php
index bd2c23e..4c6c094 100644
--- a/src/ResourceType/ConfigurableResourceTypeRepository.php
+++ b/src/ResourceType/ConfigurableResourceTypeRepository.php
@@ -9,6 +9,10 @@ use Drupal\jsonapi\ResourceType\ResourceTypeRepository;
 use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig;
 use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager;
 use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Cache\CacheBackendInterface;
 
 /**
  * Provides a repository of JSON:API configurable resource types.
@@ -57,15 +61,6 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
    */
   protected $resourceConfigs;
 
-  /**
-   * {@inheritdoc}
-   */
-  protected $cacheTags = [
-    'jsonapi_resource_types',
-    'config:jsonapi_extras.settings',
-    'config:jsonapi_resource_config_list',
-  ];
-
   /**
    * Builds the resource config ID from the entity type ID and bundle.
    *
@@ -85,6 +80,27 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
     );
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function __construct(
+    EntityTypeManagerInterface $entity_type_manager,
+    EntityTypeBundleInfoInterface $entity_bundle_info,
+    EntityFieldManagerInterface $entity_field_manager,
+    CacheBackendInterface $cache
+  ) {
+    parent::__construct($entity_type_manager, $entity_bundle_info, $entity_field_manager, $cache);
+
+    // This is needed, as the property is added in Drupal 8.8 and it is not
+    // yet present in 8.7 or the contrib version of JSON:API at the time.
+    if (property_exists($this, 'cacheTags')) {
+      $this->cacheTags = array_merge($this->cacheTags, [
+        'config:jsonapi_extras.settings',
+        'config:jsonapi_resource_config_list',
+      ]);
+    }
+  }
+
   /**
    * Injects the entity repository.
    *
-- 
GitLab