diff -u b/core/modules/breakpoint/breakpoint.module b/core/modules/breakpoint/breakpoint.module --- b/core/modules/breakpoint/breakpoint.module +++ b/core/modules/breakpoint/breakpoint.module @@ -37,0 +38,28 @@ + +/** + * Implements hook_modules_installed(). + */ +function breakpoint_modules_installed($installed_modules) { + \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); +} + +/** + * Implements hook_modules_uninstalled(). + */ +function breakpoint_modules_uninstalled($uninstalled_modules) { + \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); +} + +/** + * Implements hook_themes_enabled() + */ +function breakpoint_themes_enabled($theme_list) { + \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); +} + +/** + * Implements hook_themes_disabled() + */ +function breakpoint_themes_disabled($theme_list) { + \Drupal::service('breakpoint.manager')->clearCachedDefinitions(); +} diff -u b/core/modules/breakpoint/src/BreakpointManager.php b/core/modules/breakpoint/src/BreakpointManager.php --- b/core/modules/breakpoint/src/BreakpointManager.php +++ b/core/modules/breakpoint/src/BreakpointManager.php @@ -58,7 +58,7 @@ protected $breakpointsByGroup; /** - * Constructs a new ContextualLinkManager instance. + * Constructs a new BreakpointManager instance. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. diff -u b/core/modules/breakpoint/src/BreakpointManagerInterface.php b/core/modules/breakpoint/src/BreakpointManagerInterface.php --- b/core/modules/breakpoint/src/BreakpointManagerInterface.php +++ b/core/modules/breakpoint/src/BreakpointManagerInterface.php @@ -34 +34 @@ -} \ No newline at end of file +} diff -u b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php --- b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/src/Entity/ResponsiveImageMapping.php @@ -164,2 +164,22 @@ + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + parent::calculateDependencies(); + $group = $this->getBreakpointGroup(); + $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup($group); + foreach ($breakpoints as $breakpoint) { + if (isset($breakpoint['provider'])) { + if (\Drupal::moduleHandler()->moduleExists($breakpoint['provider'])) { + $this->addDependency('module', $breakpoint['provider']); + } + elseif (\Drupal::service('theme_handler')->themeExists($breakpoint['provider'])) { + $this->addDependency('theme', $breakpoint['provider']); + } + } + } + return $this->dependencies; + } + } diff -u b/core/themes/seven/seven.breakpoints.yml b/core/themes/seven/seven.breakpoints.yml --- b/core/themes/seven/seven.breakpoints.yml +++ b/core/themes/seven/seven.breakpoints.yml @@ -12 +12 @@ - - 1x \ No newline at end of file + - 1x --- b/core/themes/stark/stark.info.yml +++ a/core/themes/stark/stark.info.yml @@ -9,26 +9,3 @@ - css/layout.css stylesheets-remove: - normalize.css - -breakpoints: - mobile: - name: mobile - label: mobile - mediaQuery: '(min-width: 0px)' - weight: 0 - multipliers: - - 1x - narrow: - name: narrow - label: narrow - mediaQuery: 'all and (min-width: 480px) and (max-width: 959px)' - weight: 1 - multipliers: - - 1x - wide: - name: wide - label: wide - mediaQuery: 'all and (min-width: 960px)' - weight: 2 - multipliers: - - 1x --- /dev/null +++ b/core/modules/responsive_image/tests/src/ResponsiveImageMappingEntityUnitTest.php @@ -0,0 +1,153 @@ +entityTypeId = $this->randomMachineName(); + + $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); + $this->entityType->expects($this->any()) + ->method('getProvider') + ->will($this->returnValue('responsive_image')); + + $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); + $this->entityManager->expects($this->any()) + ->method('getDefinition') + ->with($this->entityTypeId) + ->will($this->returnValue($this->entityType)); + + $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface'); + + $this->breakpointManager = $this->getMock('\Drupal\breakpoint\BreakpointManagerInterface'); + + $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); + + $this->themeHandler = $this->getMock('\Drupal\Core\Extension\ThemeHandlerInterface'); + + $container = new ContainerBuilder(); + $container->set('entity.manager', $this->entityManager); + $container->set('uuid', $this->uuid); + $container->set('breakpoint.manager', $this->breakpointManager); + $container->set('module_handler', $this->moduleHandler); + $container->set('theme_handler', $this->themeHandler); + \Drupal::setContainer($container); + } + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies() { + $this->breakpointManager->expects($this->any()) + ->method('getBreakpointsByGroup') + ->with('test_group') + ->will($this->returnValue(array( + 'some_module.mobile' => array( + 'label' => 'Module Breakpoint', + 'mediaQuery' => '(min-width: 0px)', + 'provider' => 'some_module', + 'multipliers' => array('1x', '2x'), + ), + 'some_theme.narrow' => array( + 'label' => 'Theme Breakpoint', + 'mediaQuery' => 'all and (min-width: 480px) and (max-width: 959px)', + 'provider' => 'some_theme', + 'multipliers' => array('1x', '2x'), + ) + ))); + $this->moduleHandler->expects($this->any()) + ->method('moduleExists') + ->with($this->logicalOr('some_module', 'some_theme')) + ->will($this->returnCallback(array($this, 'moduleExistsMock'))); + + $this->themeHandler->expects($this->any()) + ->method('themeExists') + ->with('some_theme') + ->will($this->returnCallback(array($this, 'themeExistsMock'))); + $values = array( + 'label' => 'TestMapping', + 'breakpointGroup' => 'test_group' + ); + $mapping = new ResponsiveImageMapping($values, $this->entityTypeId); + $mapping->addMapping('some_module.mobile', '1x', 'thumbnail'); + $mapping->addMapping('some_theme.narrow', '1x', 'medium'); + $dependencies = $mapping->calculateDependencies(); + $this->assertContains('some_module', $dependencies['module']); + $this->assertContains('some_theme', $dependencies['theme']); + } + + public function moduleExistsMock($module) { + return $module == 'some_module'; + } + + public function themeExistsMock($theme) { + return $theme == 'some_theme'; + } + +} --- /dev/null +++ b/core/themes/stark/stark.breakpoints.yml @@ -0,0 +1,19 @@ +stark.mobile: + label: mobile + mediaQuery: '(min-width: 0px)' + weight: 0 + multipliers: + - 1x +stark.narrow: + label: narrow + mediaQuery: 'all and (min-width: 480px) and (max-width: 959px)' + weight: 1 + multipliers: + - 1x +stark.wide: + name: wide + label: wide + mediaQuery: 'all and (min-width: 960px)' + weight: 2 + multipliers: + - 1x