diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 18b8607..3834dae 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -100,16 +100,16 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora * The entity type definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_generator, LanguageManagerInterface $language_manager) { + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) { parent::__construct($entity_type); $this->configFactory = $config_factory; - $this->uuidGenerator = $uuid_generator; + $this->uuidService = $uuid_service; $this->languageManager = $language_manager; } @@ -446,8 +446,8 @@ public function createFromStorageRecord(array $values) { */ protected function _doCreateFromStorageRecord(array $values, $is_syncing = FALSE) { // Assign a new UUID if there is none yet. - if ($this->uuidKey && $this->uuidGenerator && !isset($values[$this->uuidKey])) { - $values[$this->uuidKey] = $this->uuidGenerator->generate(); + if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) { + $values[$this->uuidKey] = $this->uuidService->generate(); } $data = $this->mapFromStorageRecords(array($values)); $entity = current($data); diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 99ca3fc..f583121 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -63,7 +63,7 @@ * * @var \Drupal\Component\Uuid\UuidInterface */ - protected $uuidGenerator; + protected $uuidService; /** * Name of the entity class. @@ -177,8 +177,8 @@ public function create(array $values = array()) { $entity_class::preCreate($this, $values); // Assign a new UUID if there is none yet. - if ($this->uuidKey && $this->uuidGenerator && !isset($values[$this->uuidKey])) { - $values[$this->uuidKey] = $this->uuidGenerator->generate(); + if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) { + $values[$this->uuidKey] = $this->uuidService->generate(); } $entity = $this->doCreate($values); diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 252c254..478bca7 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -40,7 +40,7 @@ class KeyValueEntityStorage extends EntityStorageBase { * * @var \Drupal\Component\Uuid\UuidInterface */ - protected $uuidGenerator; + protected $uuidService; /** * The language manager. @@ -56,15 +56,15 @@ class KeyValueEntityStorage extends EntityStorageBase { * The entity type. * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value_store * The key value store. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ - public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_generator, LanguageManagerInterface $language_manager) { + public function __construct(EntityTypeInterface $entity_type, KeyValueStoreInterface $key_value_store, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) { parent::__construct($entity_type); $this->keyValueStore = $key_value_store; - $this->uuidGenerator = $uuid_generator; + $this->uuidService = $uuid_service; $this->languageManager = $language_manager; // Check if the entity type supports UUIDs. diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index b617413..134eb5e 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -168,11 +168,15 @@ public function getFieldStorageDefinitions() { * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator * The UUID service. */ - public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, UuidInterface $uuid_generator) { + public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, UuidInterface $uuid_generator = NULL) { parent::__construct($entity_type, $entity_manager, $cache); $this->database = $database; $this->languageManager = $language_manager; - $this->uuidGenerator = $uuid_generator; + + // Maintain backwards compatibility, remove in D9. + if (!$uuid_generator) { + $this->uuidService = \Drupal::service('uuid'); + } $this->initTableLayout(); } @@ -1053,8 +1057,9 @@ protected function saveRevision(ContentEntityInterface $entity) { if ($entity->isNewRevision()) { // Generating a new revision should generate a new revision UUID. - if ($this->revisionUuidKey) { - $record->{$this->revisionUuidKey} = $this->uuidGenerator->generate(); + $generate_uuid = $this->revisionUuidKey && ((!$entity->original) || $entity->original->getRevisionUuid() === $record->revision_uuid); + if ($generate_uuid) { + $record->{$this->revisionUuidKey} = $this->uuidService->generate(); } $insert_id = $this->database diff --git a/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php b/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php index be2347d..744e585 100644 --- a/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php +++ b/core/lib/Drupal/Core/Field/BaseFieldOverrideStorage.php @@ -20,15 +20,15 @@ class BaseFieldOverrideStorage extends FieldConfigStorageBase { * The entity type definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type plugin manager. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_generator, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct($entity_type, $config_factory, $uuid_generator, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_manager) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); $this->fieldTypeManager = $field_type_manager; } diff --git a/core/modules/field/src/FieldConfigStorage.php b/core/modules/field/src/FieldConfigStorage.php index f503de1..0870cd4 100644 --- a/core/modules/field/src/FieldConfigStorage.php +++ b/core/modules/field/src/FieldConfigStorage.php @@ -46,7 +46,7 @@ class FieldConfigStorage extends FieldConfigStorageBase { * The entity type definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. @@ -57,8 +57,8 @@ class FieldConfigStorage extends FieldConfigStorageBase { * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type plugin manager. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_generator, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct($entity_type, $config_factory, $uuid_generator, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); $this->entityManager = $entity_manager; $this->state = $state; $this->fieldTypeManager = $field_type_manager; diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php index e9ba050..ebb0371 100644 --- a/core/modules/field/src/FieldStorageConfigStorage.php +++ b/core/modules/field/src/FieldStorageConfigStorage.php @@ -54,7 +54,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { * The entity type definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. @@ -67,8 +67,8 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { * @param \Drupal\Component\Plugin\PluginManagerInterface\FieldTypePluginManagerInterface $field_type_manager * The field type plugin manager. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_generator, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { - parent::__construct($entity_type, $config_factory, $uuid_generator, $language_manager); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) { + parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager); $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->state = $state; diff --git a/core/modules/shortcut/src/ShortcutSetStorage.php b/core/modules/shortcut/src/ShortcutSetStorage.php index 3ba6c09..d76c0c4 100644 --- a/core/modules/shortcut/src/ShortcutSetStorage.php +++ b/core/modules/shortcut/src/ShortcutSetStorage.php @@ -30,15 +30,15 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora * The entity info for the entity type. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory service. - * @param \Drupal\Component\Uuid\UuidInterface $uuid_generator + * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ - public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_generator, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { - parent::__construct($entity_info, $config_factory, $uuid_generator, $language_manager); + public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { + parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager); $this->moduleHandler = $module_handler; }