Commit 3bbe5619 authored by alexpott's avatar alexpott

Issue #2136559 by Gábor Hojtsy: Config entity admin lists show configuration...

Issue #2136559 by Gábor Hojtsy: Config entity admin lists show configuration with overrides (eg. localized)
parent a746c55b
......@@ -21,7 +21,7 @@ class ConfigEntityListBuilder extends EntityListBuilder {
* {@inheritdoc}
*/
public function load() {
$entities = parent::load();
$entities = $this->storage->loadMultipleOverrideFree();
// Sort the entities using the entity class's sort() method.
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
......
......@@ -420,4 +420,26 @@ public function updateFromStorageRecord(ConfigEntityInterface $entity, array $va
return $entity;
}
/**
* {@inheritdoc}
*/
public function loadOverrideFree($id) {
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$entity = $this->load($id);
$this->configFactory->setOverrideState($old_state);
return $entity;
}
/**
* {@inheritdoc}
*/
public function loadMultipleOverrideFree(array $ids = NULL) {
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$entities = $this->loadMultiple($ids);
$this->configFactory->setOverrideState($old_state);
return $entities;
}
}
......@@ -65,4 +65,27 @@ public function createFromStorageRecord(array $values);
*/
public function updateFromStorageRecord(ConfigEntityInterface $entity, array $values);
/**
* Loads one entity in their original form without overrides.
*
* @param mixed $id
* The ID of the entity to load.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* An entity object. NULL if no matching entity is found.
*/
public function loadOverrideFree($id);
/**
* Loads one or more entities in their original form without overrides.
*
* @param $ids
* An array of entity IDs, or NULL to load all entities.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* An array of entity objects indexed by their IDs. Returns an empty array
* if no matching entities found.
*/
public function loadMultipleOverrideFree(array $ids = NULL);
}
<?php
/**
* @file
* Contains \Drupal\Core\Entity\KeyValueStore\KeyValueConfigEntityStorage.
*/
namespace Drupal\Core\Entity\KeyValueStore;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides a key value backend for configuration entities.
*/
class KeyValueConfigEntityStorage extends KeyValueEntityStorage implements ConfigEntityStorageInterface {
/**
* {@inheritdoc}
*/
public static function getIDFromConfigName($config_name, $config_prefix) {
// @todo Implement and test. See https://www.drupal.org/node/2406645
}
/**
* {@inheritdoc}
*/
public function createFromStorageRecord(array $values) {
// @todo Implement and test. See https://www.drupal.org/node/2406645
}
/**
* {@inheritdoc}
*/
public function updateFromStorageRecord(ConfigEntityInterface $entity, array $values) {
// @todo Implement and test. See https://www.drupal.org/node/2406645
}
/**
* {@inheritdoc}
*/
public function loadOverrideFree($id) {
// KeyValueEntityStorage does not support storing and retrieving overrides,
// it does not use the configuration factory. This is just a test method.
// See https://www.drupal.org/node/2393751.
return $this->load($id);
}
/**
* {@inheritdoc}
*/
public function loadMultipleOverrideFree(array $ids = NULL) {
// KeyValueEntityStorage does not support storing and retrieving overrides,
// it does not use the configuration factory. This is just a test method.
// See https://www.drupal.org/node/2393751.
return $this->loadMultiple($ids);
}
}
......@@ -10,7 +10,7 @@
use Drupal\simpletest\WebTestBase;
/**
* Tests that config overrides do not bleed through in entity forms.
* Tests that config overrides do not bleed through in entity forms and lists.
*
* @group config
*/
......@@ -22,39 +22,50 @@ class ConfigEntityFormOverrideTest extends WebTestBase {
public static $modules = array('config_test');
/**
* Tests that overrides do not affect forms.
* Tests that overrides do not affect forms or listing screens.
*/
public function testFormsWithOverrides() {
$overridden_name = 'Overridden label';
$original_label = 'Default';
$overridden_label = 'Overridden label';
$edited_label = 'Edited label';
// Set up an override.
$settings['config']['config_test.dynamic.dotted.default']['label'] = (object) array(
'value' => $overridden_name,
'value' => $overridden_label,
'required' => TRUE,
);
$this->writeSettings($settings);
// Test that everything on the form is the same, but that the override
// worked for the config entity label.
// Test that the overridden label is loaded with the entity.
$this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label);
// Test that the original label on the listing page is intact.
$this->drupalGet('admin/structure/config_test');
$this->assertText($overridden_name);
$this->assertText($original_label);
$this->assertNoText($overridden_label);
// Test that the original label on the editing page is intact.
$this->drupalGet('admin/structure/config_test/manage/dotted.default');
$elements = $this->xpath('//input[@name="label"]');
$this->assertIdentical((string) $elements[0]['value'], 'Default');
$this->assertNoText($overridden_name);
$this->assertIdentical((string) $elements[0]['value'], $original_label);
$this->assertNoText($overridden_label);
// Change to a new label and test that the listing now has the edited label.
$edit = array(
'label' => 'Custom label',
'label' => $edited_label,
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('admin/structure/config_test');
$this->assertText($overridden_name);
$this->assertNoText($edit['label']);
$this->assertNoText($overridden_label);
$this->assertText($edited_label);
// Test that the editing page now has the edited label.
$this->drupalGet('admin/structure/config_test/manage/dotted.default');
$elements = $this->xpath('//input[@name="label"]');
$this->assertIdentical((string) $elements[0]['value'], $edit['label']);
$this->assertIdentical((string) $elements[0]['value'], $edited_label);
// Test that the overridden label is still loaded with the entity.
$this->assertEqual(config_test_load('dotted.default')->label(), $overridden_label);
}
}
......@@ -11,7 +11,7 @@
function keyvalue_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
if (isset($entity_types['config_test'])) {
$entity_types['config_test']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage');
$entity_types['config_test']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueConfigEntityStorage');
}
if (isset($entity_types['entity_test_label'])) {
$entity_types['entity_test_label']->setStorageClass('Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment