Issue #2419059 by chx: Impossible to enable views if entities are not in SQL
parent
95a0059a74
commit
69e817c920
|
@ -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();
|
||||
|
|
|
@ -517,4 +517,11 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface,
|
|||
return array_keys($this->third_party_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isInstallable() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
id: isinstallable
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1244,4 +1244,12 @@ class ViewUI implements ViewEntityInterface {
|
|||
public function getViewExecutable() {
|
||||
return $this->storage->getViewExecutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isInstallable() {
|
||||
return $this->storage->isInstallable();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue