diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 48168ec..1b0aefb 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -14,6 +14,7 @@ use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\StorageInterface; +use Drupal\Component\Uuid\UuidInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -73,6 +74,13 @@ class ConfigStorageController implements EntityStorageControllerInterface, Entit protected $uuidKey = 'uuid'; /** + * The Uuid service. + * + * @var \Drupal\Core\Component\Uuid\UuidInterface + */ + protected $uuidService; + + /** * Name of the entity's status key or FALSE if a status is not supported. * * @var string|bool @@ -105,7 +113,7 @@ class ConfigStorageController implements EntityStorageControllerInterface, Entit * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage service. */ - public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage) { + public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service) { $this->entityType = $entity_type; $this->entityInfo = $entity_info; $this->hookLoadArguments = array(); @@ -120,6 +128,7 @@ public function __construct($entity_type, array $entity_info, ConfigFactory $con $this->configFactory = $config_factory; $this->configStorage = $config_storage; + $this->uuidService = $uuid_service; } /** @@ -130,7 +139,8 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_type, $entity_info, $container->get('config.factory'), - $container->get('config.storage') + $container->get('config.storage'), + $container->get('uuid') ); } @@ -339,8 +349,7 @@ public function create(array $values) { // Assign a new UUID if there is none yet. if (!isset($entity->{$this->uuidKey})) { - // @todo use the Uuid service once we can inject into entity controllers. - $entity->{$this->uuidKey} = \Drupal::service('uuid')->generate(); + $entity->{$this->uuidKey} = $this->uuidService->generate(); } // Modules might need to add or change the data initially held by the new diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 5a7e50e..8804827 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Database\Connection; - +use Drupal\Component\Uuid\UuidInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -91,6 +91,13 @@ class DatabaseStorageController implements EntityStorageControllerInterface, Ent protected $uuidKey; /** + * The Uuid service. + * + * @var \Drupal\Core\Component\Uuid\UuidInterface + */ + protected $uuidService; + + /** * Name of entity's revision database table field, if it supports revisions. * * Has the value FALSE if this entity does not use revisions. @@ -129,7 +136,8 @@ public static function createInstance(ContainerInterface $container, $entity_typ return new static( $entity_type, $entity_info, - $container->get('database') + $container->get('database'), + $container->get('uuid') ); } @@ -143,10 +151,12 @@ public static function createInstance(ContainerInterface $container, $entity_typ * @param \Drupal\Core\Database\Connection $database * The database connection to be used. */ - public function __construct($entity_type, array $entity_info, Connection $database) { + public function __construct($entity_type, array $entity_info, Connection $database, UuidInterface $uuid_service) { $this->database = $database; $this->entityType = $entity_type; $this->entityInfo = $entity_info; + $this->uuidService = $uuid_service; + $this->entityCache = array(); $this->hookLoadArguments = array(); @@ -480,8 +490,7 @@ public function create(array $values) { // Assign a new UUID if there is none yet. if ($this->uuidKey && !isset($entity->{$this->uuidKey})) { - // @todo use the Uuid service once we can inject into entity controllers. - $entity->{$this->uuidKey} = \Drupal::service('uuid')->generate(); + $entity->{$this->uuidKey} = $this->uuidService->generate(); } // Modules might need to add or change the data initially held by the new diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index 9b7c392..5766010 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -9,13 +9,12 @@ use Drupal\Core\Language\Language; use PDO; - use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\TypedData\ComplexDataInterface; -use Drupal\Component\Uuid\Uuid; +use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Database\Connection; /** @@ -54,8 +53,8 @@ class DatabaseStorageControllerNG extends DatabaseStorageController { /** * Overrides DatabaseStorageController::__construct(). */ - public function __construct($entity_type, array $entity_info, Connection $database) { - parent::__construct($entity_type,$entity_info, $database); + public function __construct($entity_type, array $entity_info, Connection $database, UuidInterface $uuid_service) { + parent::__construct($entity_type,$entity_info, $database, $uuid_service); $this->bundleKey = !empty($this->entityInfo['entity_keys']['bundle']) ? $this->entityInfo['entity_keys']['bundle'] : FALSE; $this->entityClass = $this->entityInfo['class']; @@ -115,8 +114,7 @@ public function create(array $values) { // Assign a new UUID if there is none yet. if ($this->uuidKey && !isset($entity->{$this->uuidKey}->value)) { - // @todo use the Uuid service once we can inject into entity controllers. - $entity->{$this->uuidKey} = \Drupal::service('uuid')->generate(); + $entity->{$this->uuidKey} = $this->uuidService->generate(); } // Modules might need to add or change the data initially held by the new diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index 6a3eddb..54d3cea 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Database\Connection; +use Drupal\Component\Uuid\UuidInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Cmf\Component\Routing\RouteProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -56,8 +57,8 @@ class MenuLinkStorageController extends DatabaseStorageController { * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider * The route provider service. */ - public function __construct($entity_type, array $entity_info, Connection $database, RouteProviderInterface $route_provider) { - parent::__construct($entity_type, $entity_info, $database); + public function __construct($entity_type, array $entity_info, Connection $database, UuidInterface $uuid_service, RouteProviderInterface $route_provider) { + parent::__construct($entity_type, $entity_info, $database, $uuid_service); $this->routeProvider = $route_provider; @@ -74,6 +75,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_type, $entity_info, $container->get('database'), + $container->get('uuid'), $container->get('router.route_provider') ); } diff --git a/core/modules/user/lib/Drupal/user/UserStorageController.php b/core/modules/user/lib/Drupal/user/UserStorageController.php index e282226..aa27995 100644 --- a/core/modules/user/lib/Drupal/user/UserStorageController.php +++ b/core/modules/user/lib/Drupal/user/UserStorageController.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Password\PasswordInterface; use Drupal\Core\Database\Connection; +use Drupal\Component\Uuid\UuidInterface; use Drupal\user\UserDataInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -51,8 +52,8 @@ class UserStorageController extends DatabaseStorageController { * @param \Drupal\user\UserDataInterface $user_data * The user data service. */ - public function __construct($entity_type, $entity_info, Connection $database, PasswordInterface $password, UserDataInterface $user_data) { - parent::__construct($entity_type, $entity_info, $database); + public function __construct($entity_type, $entity_info, Connection $database, UuidInterface $uuid_service, PasswordInterface $password, UserDataInterface $user_data) { + parent::__construct($entity_type, $entity_info, $database, $uuid_service); $this->password = $password; $this->userData = $user_data; @@ -66,6 +67,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ $entity_type, $entity_info, $container->get('database'), + $container->get('uuid'), $container->get('password'), $container->get('user.data') );