diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 1527ac6..8e0d081 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -284,6 +284,13 @@ protected function has($id, EntityInterface $entity) { } /** + * {@inheritdoc} + */ + public function hasData() { + return (bool) $this->configFactory->listAll($this->getPrefix()); + } + + /** * Gets entities from the static cache. * * @param array $ids diff --git a/core/lib/Drupal/Core/Entity/DynamicallyFieldableEntityStorageInterface.php b/core/lib/Drupal/Core/Entity/DynamicallyFieldableEntityStorageInterface.php index 5037628..9aaf35e 100644 --- a/core/lib/Drupal/Core/Entity/DynamicallyFieldableEntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/DynamicallyFieldableEntityStorageInterface.php @@ -23,14 +23,6 @@ interface DynamicallyFieldableEntityStorageInterface extends FieldableEntityStorageInterface, FieldStorageDefinitionListenerInterface { /** - * Determines if the storage contains any data. - * - * @return bool - * TRUE if the storage contains data, FALSE if not. - */ - public function hasData(); - - /** * Reacts to the creation of a field. * * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition diff --git a/core/lib/Drupal/Core/Entity/EntityStorageInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageInterface.php index 387e0fb..9be8c19 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageInterface.php @@ -148,6 +148,14 @@ public function delete(array $entities); public function save(EntityInterface $entity); /** + * Determines if the storage contains any data. + * + * @return bool + * TRUE if the storage contains data, FALSE if not. + */ + public function hasData(); + + /** * Returns an entity query instance. * * @param string $conjunction diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 365020c..8e0d850 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -202,6 +202,13 @@ protected function has($id, EntityInterface $entity) { /** * {@inheritdoc} */ + public function hasData() { + return (bool) $this->keyValueStore->getAll(); + } + + /** + * {@inheritdoc} + */ protected function getQueryServiceName() { return 'entity.query.keyvalue'; } diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php index 7cf16e6..17e1cd0 100644 --- a/core/modules/config/src/Tests/ConfigEntityTest.php +++ b/core/modules/config/src/Tests/ConfigEntityTest.php @@ -39,6 +39,10 @@ class ConfigEntityTest extends WebTestBase { */ function testCRUD() { $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); + + $storage = \Drupal::entityManager()->getStorage('config_test'); + $this->assertFalse($storage->hasData()); + // Verify default properties on a newly created empty entity. $empty = entity_create('config_test'); $this->assertTrue($empty->uuid()); @@ -80,6 +84,8 @@ function testCRUD() { $this->pass('EntityMalformedException was thrown.'); } + $this->assertTrue($storage->hasData()); + // Verify that an entity with an empty ID string is considered empty, too. $empty_id = entity_create('config_test', array( 'id' => '',