From 69e817c9206b0c34918c0cd83ba62e350aa7c04a Mon Sep 17 00:00:00 2001 From: catch Date: Sun, 22 Feb 2015 09:29:01 +0000 Subject: [PATCH] Issue #2419059 by chx: Impossible to enable views if entities are not in SQL --- core/lib/Drupal/Core/Config/ConfigInstaller.php | 5 ++++- .../Drupal/Core/Config/Entity/ConfigEntityBase.php | 7 +++++++ .../Core/Config/Entity/ConfigEntityInterface.php | 11 +++++++++++ core/modules/config/src/Tests/ConfigImporterTest.php | 12 ++++++++++++ .../config_test.dynamic.isinstallable.default.yml | 4 ++++ .../tests/config_test/src/Entity/ConfigTest.php | 7 +++++++ core/modules/views/src/Entity/View.php | 8 ++++++++ core/modules/views_ui/src/ViewUI.php | 8 ++++++++ 8 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 core/modules/config/tests/config_test/config/install/config_test.dynamic.isinstallable.default.yml diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 1c7993bf8499..8065613fc1ad 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -218,6 +218,7 @@ class ConfigInstaller implements ConfigInstallerInterface { if ($this->isSyncing) { continue; } + /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */ $entity_storage = $this->configManager ->getEntityManager() ->getStorage($entity_type); @@ -231,7 +232,9 @@ class ConfigInstaller implements ConfigInstallerInterface { else { $entity = $entity_storage->createFromStorageRecord($new_config->get()); } - $entity->save(); + if ($entity->isInstallable()) { + $entity->save(); + } } else { $new_config->save(); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 7d684e0af96b..ec09fd528633 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -517,4 +517,11 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface, return array_keys($this->third_party_settings); } + /** + * {@inheritdoc} + */ + public function isInstallable() { + return TRUE; + } + } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index 1db3b422ee26..a434ac11cd89 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -192,4 +192,15 @@ interface ConfigEntityInterface extends EntityInterface { */ public function getDependencies(); + /** + * Checks whether this entity is installable. + * + * For example, a default view might not be installable if the base table + * doesn't exist. + * + * @retun bool + * TRUE if the entity is installable, FALSE otherwise. + */ + public function isInstallable(); + } diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php index d2c7cf0a3e97..b4cb9de3880b 100644 --- a/core/modules/config/src/Tests/ConfigImporterTest.php +++ b/core/modules/config/src/Tests/ConfigImporterTest.php @@ -526,4 +526,16 @@ class ConfigImporterTest extends KernelTestBase { $logs = $this->configImporter->getErrors(); $this->assertEqual(count($logs), 0); } + + /** + * Tests the isInstallable method() + */ + function testIsInstallable() { + $config_name = 'config_test.dynamic.isinstallable'; + $this->assertFalse($this->container->get('config.storage')->exists($config_name)); + \Drupal::state()->set('config_test.isinstallable', TRUE); + $this->installConfig(array('config_test')); + $this->assertTrue($this->container->get('config.storage')->exists($config_name)); + } + } diff --git a/core/modules/config/tests/config_test/config/install/config_test.dynamic.isinstallable.default.yml b/core/modules/config/tests/config_test/config/install/config_test.dynamic.isinstallable.default.yml new file mode 100644 index 000000000000..36336a558b3a --- /dev/null +++ b/core/modules/config/tests/config_test/config/install/config_test.dynamic.isinstallable.default.yml @@ -0,0 +1,4 @@ +id: isinstallable +label: Default +weight: 0 +protected_property: Default diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php index 4a2a11b2c6c0..0cc207e48ea1 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigTest.php @@ -154,4 +154,11 @@ class ConfigTest extends ConfigEntityBase implements ConfigTestInterface { return $this; } + /** + * {@inheritdoc} + */ + public function isInstallable() { + return $this->id != 'isinstallable' || \Drupal::state()->get('config_test.isinstallable'); + } + } diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index e6e6e29e3349..ecd541ed2a26 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -425,4 +425,12 @@ class View extends ConfigEntityBase implements ViewEntityInterface { } $this->set('display', $displays); } + + /** + * {@inheritdoc} + */ + public function isInstallable() { + return (bool) \Drupal::service('views.views_data')->get($this->base_table); + } + } diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php index b8c6cd2ee591..1d3c8be631de 100644 --- a/core/modules/views_ui/src/ViewUI.php +++ b/core/modules/views_ui/src/ViewUI.php @@ -1244,4 +1244,12 @@ class ViewUI implements ViewEntityInterface { public function getViewExecutable() { return $this->storage->getViewExecutable(); } + + /** + * {@inheritdoc} + */ + public function isInstallable() { + return $this->storage->isInstallable(); + } + }