Commit 753a5485 authored by webchick's avatar webchick

Issue #2097259 by vijaycs85, tstoeckler: Add hasConfigSchema() method.

parent 45217937
......@@ -11,11 +11,12 @@
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\TypedConfigManagerInterface;
/**
* Manages config type plugins.
*/
class TypedConfigManager extends PluginManagerBase {
class TypedConfigManager extends PluginManagerBase implements TypedConfigManagerInterface {
/**
* A storage controller instance for reading configuration data.
......@@ -285,4 +286,14 @@ protected function replaceVariable($value, $data) {
}
}
/**
* {@inheritdoc}
*/
public function hasConfigSchema($name) {
// The schema system falls back on the Property class for unknown types.
// See http://drupal.org/node/1905230
$definition = $this->getDefinition($name);
return is_array($definition) && ($definition['class'] != '\Drupal\Core\Config\Schema\Property');
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Config\TypedConfigManagerInterface.
*/
namespace Drupal\Core\Config;
/**
* Defines an interface for typed configuration manager.
*
* @package Drupal\Core\Config
*/
Interface TypedConfigManagerInterface {
/**
* Checks if the configuration schema with the given config name exists.
*
* @param string $name
* Configuration name.
*
* @return bool
* TRUE if configuration schema exists, FALSE otherwise.
*/
public function hasConfigSchema($name);
}
......@@ -44,6 +44,7 @@ public function setUp() {
*/
function testSchemaMapping() {
// Nonexistent configuration key will have Unknown as metadata.
$this->assertIdentical(FALSE, config_typed()->hasConfigSchema('config_test.no_such_key'));
$definition = config_typed()->getDefinition('config_test.no_such_key');
$expected = array();
$expected['label'] = 'Unknown';
......@@ -51,10 +52,12 @@ function testSchemaMapping() {
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for nonexistent configuration.');
// Configuration file without schema will return Unknown as well.
$this->assertIdentical(FALSE, config_typed()->hasConfigSchema('config_test.noschema'));
$definition = config_typed()->getDefinition('config_test.noschema');
$this->assertEqual($definition, $expected, 'Retrieved the right metadata for configuration with no schema.');
// Configuration file with only some schema.
$this->assertIdentical(TRUE, config_typed()->hasConfigSchema('config_test.someschema'));
$definition = config_typed()->getDefinition('config_test.someschema');
$expected = array();
$expected['label'] = 'Schema test data';
......
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