diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageController.php b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageController.php similarity index 44% rename from core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageController.php rename to core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageController.php index f4bf884..cd7a2cd 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageController.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageController.php @@ -7,16 +7,75 @@ namespace Drupal\breakpoint; +use Drupal\Component\Uuid\UuidInterface; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Entity\ConfigStorageController; +use Drupal\Core\Config\Entity\ConfigStorageControllerInterface; +use Drupal\Core\Config\StorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\Query\QueryFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * Provides storage for breakpoint groups. + */ class BreakpointGroupStorageController extends ConfigStorageController implements BreakpointGroupStorageControllerInterface { /** + * The breakpoint entity type. + * + * @var \Drupal\Core\Entity\EntityTypeInterface + */ + protected $breakpointEntityType; + + /** + * The breakpoint storage. + * + * @var \Drupal\Core\Config\Entity\ConfigStorageControllerInterface + */ + protected $breakpointStorage; + + /** + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + * @param \Drupal\Core\Config\StorageInterface $config_storage + * The config storage service. + * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory + * The entity query factory. + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service + * The UUID service. + * @param \Drupal\Core\Entity\EntityTypeInterface $breakpoint_entity_type + * The breakpoint entity type. + * @param \Drupal\Core\Config\Entity\ConfigStorageControllerInterface $breakpoint_storage + * The breakpoint storage. + */ + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityTypeInterface $breakpoint_entity_type, ConfigStorageControllerInterface $breakpoint_storage) { + parent::__construct($entity_type, $config_factory, $config_storage, $entity_query_factory, $uuid_service); + + $this->breakpointEntityType = $breakpoint_entity_type; + $this->breakpointStorage = $breakpoint_storage; + } + + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + $entity_manager = $container->get('entity.manager'); + return new static( + $entity_type, + $container->get('config.factory'), + $container->get('config.storage'), + $container->get('entity.query'), + $container->get('uuid'), + $entity_manager->getDefinition('breakpoint'), + $entity_manager->getStorageController('breakpoint') + ); + } + + /** * {@inheritdoc} */ function deleteBreakpointsBySource(array $list, $source_type) { - $ids = \Drupal::configFactory()->listAll('breakpoint.breakpoint_group.' . $source_type . '.'); - $entity_manager = \Drupal::entityManager(); + $ids = $this->configFactory->listAll('breakpoint.breakpoint_group.' . $source_type . '.'); $breakpoint_group_type = $this->getEntityType(); // Remove the breakpoint.breakpoint part of the breakpoint identifier. @@ -31,14 +90,13 @@ function deleteBreakpointsBySource(array $list, $source_type) { $breakpoint_group->delete(); // Get all breakpoints defined by this theme/module. - $breakpoint_ids = \Drupal::service('config.storage')->listAll('breakpoint.breakpoint.' . $source_type . '.' . $breakpoint_group->id() . '.'); - $breakpoint_type = $entity_manager->getDefinition('breakpoint'); + $breakpoint_ids = $this->configStorage->listAll('breakpoint.breakpoint.' . $source_type . '.' . $breakpoint_group->id() . '.'); // Remove the breakpoint.breakpoint part of the breakpoint identifier. foreach ($breakpoint_ids as &$breakpoint_id) { - $breakpoint_id = static::getIDFromConfigName($breakpoint_id, $breakpoint_type->getConfigPrefix()); + $breakpoint_id = static::getIDFromConfigName($breakpoint_id, $this->breakpointEntityType->getConfigPrefix()); } - $breakpoints = $entity_manager->getStorageController('breakpoint')->loadMultiple($breakpoint_ids); + $breakpoints = $this->breakpointStorage->loadMultiple($breakpoint_ids); // Make sure we only delete breakpoints defined by this theme/module. foreach ($breakpoints as $breakpoint) { @@ -60,12 +118,12 @@ function deleteBreakpointsBySource(array $list, $source_type) { /** * Removes breakpoint groups from all disabled themes or uninstalled modules. * - * @param array $group_id + * @param string $group_id * Machine readable name of the breakpoint group. * @param string $source_type * Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE. */ - protected function deleteBreakpointGroupsBySource(array $group_id, $source_type) { + protected function deleteBreakpointGroupsBySource($group_id, $source_type) { $breakpoint_groups = $this->loadMultiple(); foreach ($breakpoint_groups as $breakpoint_group) { if ($breakpoint_group->sourceType == $source_type && $breakpoint_group->source == $group_id) { @@ -73,4 +131,5 @@ protected function deleteBreakpointGroupsBySource(array $group_id, $source_type) } } } -} \ No newline at end of file + +} diff --git a/core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageControllerInterface.php b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageControllerInterface.php similarity index 89% rename from core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageControllerInterface.php rename to core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageControllerInterface.php index 2a21c60..a45828f 100644 --- a/core/modules/breakpoint/lib/Drupal/breakpoint/Controller/BreakpointGroupStorageControllerInterface.php +++ b/core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupStorageControllerInterface.php @@ -10,7 +10,7 @@ use Drupal\Core\Config\Entity\ConfigStorageControllerInterface; /** - * Defines a common interface for breakpoint entity controller classes. + * Provides an interface for breakpoint group storage. */ interface BreakpointGroupStorageControllerInterface extends ConfigStorageControllerInterface { @@ -23,4 +23,5 @@ * Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE. */ public function deleteBreakpointsBySource(array $list, $source_type); + }