diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php index 3e8440e..5c83037 100644 --- a/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php @@ -8,6 +8,7 @@ namespace Drupal\responsive_image\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; +use Drupal\image\Entity\ImageStyle; use Drupal\responsive_image\ResponsiveImageMappingInterface; /** @@ -178,6 +179,12 @@ public function calculateDependencies() { foreach ($providers as $provider => $type) { $this->addDependency($type, $provider); } + foreach ($this->getMappings() as $mapping) { + $style = ImageStyle::load($mapping['image_style']); + if ($style) { + $this->addDependency('config', $style->getConfigDependencyName()); + } + } return $this->dependencies; } diff --git a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageMappingConfigEntityUnitTest.php b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageMappingConfigEntityUnitTest.php index df8a0ab..4dd78d4 100644 --- a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageMappingConfigEntityUnitTest.php +++ b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageMappingConfigEntityUnitTest.php @@ -65,8 +65,33 @@ protected function setUp() { * @covers ::calculateDependencies */ public function testCalculateDependencies() { + // Set up image style loading mock. + $image_style_entity = $this->getMock('Drupal\Core\Config\Entity\ConfigEntityInterface'); + $image_style_entity->expects($this->any()) + ->method('getConfigDependencyName') + ->willReturn('image.style.test_style'); + $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); + $storage->expects($this->at(0)) + ->method('load') + ->with('test_style') + ->willReturn($image_style_entity); + $storage->expects($this->at(1)) + ->method('load') + ->with('') + ->willReturn(NULL); + $this->entityManager->expects($this->any()) + ->method('getStorage') + ->with('image_style') + ->willReturn($storage); + $this->entityManager->expects($this->any()) + ->method('getEntityTypeFromClass') + ->with('Drupal\image\Entity\ImageStyle') + ->willReturn('image_style'); + $entity = new ResponsiveImageMapping(array('breakpointGroup' => 'test_group')); $entity->setBreakpointGroup('test_group'); + $entity->addMapping('test_breakpoint', '1x', 'test_style'); + $entity->addMapping('test_breakpoint', '2x', ''); $this->breakpointManager->expects($this->any()) ->method('getGroupProviders') @@ -76,6 +101,7 @@ public function testCalculateDependencies() { $dependencies = $entity->calculateDependencies(); $this->assertContains('toolbar', $dependencies['module']); $this->assertContains('bartik', $dependencies['theme']); + $this->assertContains('image.style.test_style', $dependencies['config']); } /**