Commit 380cdbc6 authored by catch's avatar catch
Browse files

Issue #1849792 by damiankloip: Abstract usage of 'config_prefix' on...

Issue #1849792 by damiankloip: Abstract usage of 'config_prefix' on ConfigStorageController into getConfigPrefix method.
parent 23c83da4
......@@ -136,6 +136,16 @@ public function loadByProperties(array $values = array()) {
return array();
}
/**
* Returns the config prefix used by the configuration entity type.
*
* @return string
* The full configuration prefix, for example 'views.view.'.
*/
public function getConfigPrefix() {
return $this->entityInfo['config_prefix'] . '.';
}
/**
* Builds the query to load the entity.
*
......@@ -159,7 +169,7 @@ public function loadByProperties(array $values = array()) {
*/
protected function buildQuery($ids, $revision_id = FALSE) {
$config_class = $this->entityInfo['class'];
$prefix = $this->entityInfo['config_prefix'] . '.';
$prefix = $this->getConfigPrefix();
// Load all of the configuration entities.
if ($ids === NULL) {
......@@ -251,7 +261,7 @@ public function delete(array $entities) {
}
foreach ($entities as $id => $entity) {
$config = config($this->entityInfo['config_prefix'] . '.' . $entity->id());
$config = config($this->getConfigPrefix() . $entity->id());
$config->delete();
// Remove the entity from the manifest file.
......@@ -273,7 +283,7 @@ public function delete(array $entities) {
* When attempting to save a configuration entity that has no ID.
*/
public function save(EntityInterface $entity) {
$prefix = $this->entityInfo['config_prefix'] . '.';
$prefix = $this->getConfigPrefix();
// Configuration entity IDs are strings, and '0' is a valid ID.
$id = $entity->id();
......@@ -323,9 +333,9 @@ public function save(EntityInterface $entity) {
// Add this entity to the manifest file if necessary.
$config = config('manifest.' . $this->entityInfo['config_prefix']);
$manifest = $config->get();
if (!in_array($this->entityInfo['config_prefix'] . '.' . $entity->id(), $manifest)) {
if (!in_array($this->getConfigPrefix() . $entity->id(), $manifest)) {
$manifest[$entity->id()] = array(
'name' => $this->entityInfo['config_prefix'] . '.' . $entity->id(),
'name' => $this->getConfigPrefix() . $entity->id(),
);
$config->setData($manifest)->save();
}
......
<?php
/**
* @file
* Contains Drupal\config\Tests\ConfigEntityUnitTest.
*/
namespace Drupal\config\Tests;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Unit tests for configuration controllers and objects.
*/
class ConfigEntityUnitTest extends DrupalUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_test');
public static function getInfo() {
return array(
'name' => 'Configuration entity methods',
'description' => 'Unit tests for configuration entity base methods.',
'group' => 'Configuration',
);
}
/**
* Tests storage controller methods.
*/
public function testStorageControllerMethods() {
$controller = entity_get_controller('config_test');
$info = entity_get_info('config_test');
$expected = $info['config_prefix'] . '.';
$this->assertIdentical($controller->getConfigPrefix(), $expected);
}
}
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