Skip to content
Snippets Groups Projects
Commit e8fa2b37 authored by catch's avatar catch
Browse files

Issue #3501508 by prudloff, smustgrave: Add a way to programmatically generate...

Issue #3501508 by prudloff, smustgrave: Add a way to programmatically generate bundle list cache tags
parent cafc9d25
No related branches found
No related tags found
4 merge requests!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #449491 passed with warnings
Pipeline: drupal

#449497

    Pipeline: drupal

    #449493

      ...@@ -483,7 +483,10 @@ public function getCacheContexts() { ...@@ -483,7 +483,10 @@ public function getCacheContexts() {
      protected function getListCacheTagsToInvalidate() { protected function getListCacheTagsToInvalidate() {
      $tags = $this->getEntityType()->getListCacheTags(); $tags = $this->getEntityType()->getListCacheTags();
      if ($this->getEntityType()->hasKey('bundle')) { if ($this->getEntityType()->hasKey('bundle')) {
      $tags[] = $this->getEntityTypeId() . '_list:' . $this->bundle(); $tags = Cache::mergeTags(
      $tags,
      $this->getEntityType()->getBundleListCacheTags($this->bundle())
      );
      } }
      return $tags; return $tags;
      } }
      ......
      ...@@ -865,6 +865,13 @@ public function getListCacheTags() { ...@@ -865,6 +865,13 @@ public function getListCacheTags() {
      return $this->list_cache_tags; return $this->list_cache_tags;
      } }
      /**
      * {@inheritdoc}
      */
      public function getBundleListCacheTags(string $bundle): array {
      return [$this->id() . '_list:' . $bundle];
      }
      /** /**
      * {@inheritdoc} * {@inheritdoc}
      */ */
      ......
      ...@@ -733,6 +733,17 @@ public function getListCacheContexts(); ...@@ -733,6 +733,17 @@ public function getListCacheContexts();
      */ */
      public function getListCacheTags(); public function getListCacheTags();
      /**
      * The list cache tags associated with a specific bundle.
      *
      * Enables code listing entities of this type and bundle to ensure that newly created
      * entities show up immediately.
      *
      * @return string[]
      * An array of the cache tags for this bundle.
      */
      public function getBundleListCacheTags(string $bundle): array;
      /** /**
      * Gets the key that is used to store configuration dependencies. * Gets the key that is used to store configuration dependencies.
      * *
      ......
      ...@@ -487,4 +487,15 @@ public function testEntityClassImplements(): void { ...@@ -487,4 +487,15 @@ public function testEntityClassImplements(): void {
      $this->assertFalse($entity_type->entityClassImplements(\DateTimeInterface::class)); $this->assertFalse($entity_type->entityClassImplements(\DateTimeInterface::class));
      } }
      /**
      * Tests the ::getBundleListCacheTags() method.
      *
      * @covers ::getBundleListCacheTags
      */
      public function testGetBundleListCacheTags(): void {
      $entity_type = $this->setUpEntityType(['entity_keys' => ['id' => 'id']]);
      $bundle = $this->randomMachineName();
      $this->assertEquals([$entity_type->id() . '_list:' . $bundle], $entity_type->getBundleListCacheTags($bundle));
      }
      } }
      ...@@ -102,6 +102,10 @@ protected function setUp(): void { ...@@ -102,6 +102,10 @@ protected function setUp(): void {
      $this->entityType->expects($this->any()) $this->entityType->expects($this->any())
      ->method('getListCacheTags') ->method('getListCacheTags')
      ->willReturn([$this->entityTypeId . '_list']); ->willReturn([$this->entityTypeId . '_list']);
      $this->entityType->expects($this->any())
      ->method('getBundleListCacheTags')
      ->with($this->entityTypeId)
      ->willReturn([$this->entityTypeId . '_list:' . $this->entityTypeId]);
      $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class); $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
      $this->entityTypeManager->expects($this->any()) $this->entityTypeManager->expects($this->any())
      ......
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Please register or to comment