Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -48,7 +48,15 @@ class BootstrapConfigStorageFactory {
|
|||
/**
|
||||
* Returns a File-based configuration storage implementation.
|
||||
*
|
||||
* If there is no active configuration directory calling this method will
|
||||
* result in an error.
|
||||
*
|
||||
* @return \Drupal\Core\Config\FileStorage
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core
|
||||
* no longer creates an active directory.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getFileStorage() {
|
||||
return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
|
||||
|
|
|
@ -108,8 +108,8 @@ class Config extends StorableConfigBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setData(array $data, $validate_keys = TRUE) {
|
||||
parent::setData($data, $validate_keys);
|
||||
public function setData(array $data) {
|
||||
parent::setData($data);
|
||||
$this->resetOverriddenData();
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\Core\Config;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
|
||||
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
|
||||
|
@ -153,10 +154,6 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
*
|
||||
* @param array $data
|
||||
* The new configuration data.
|
||||
* @param bool $validate_keys
|
||||
* (optional) Whether the data should be verified for valid keys. Set to
|
||||
* FALSE if the $data is known to be valid already (for example, being
|
||||
* loaded from the config storage).
|
||||
*
|
||||
* @return $this
|
||||
* The configuration object.
|
||||
|
@ -164,10 +161,9 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
* @throws \Drupal\Core\Config\ConfigValueException
|
||||
* If any key in $data in any depth contains a dot.
|
||||
*/
|
||||
public function setData(array $data, $validate_keys = TRUE) {
|
||||
if ($validate_keys) {
|
||||
$this->validateKeys($data);
|
||||
}
|
||||
public function setData(array $data) {
|
||||
$data = $this->castSafeStrings($data);
|
||||
$this->validateKeys($data);
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
@ -187,6 +183,7 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
* If $value is an array and any of its keys in any depth contains a dot.
|
||||
*/
|
||||
public function set($key, $value) {
|
||||
$value = $this->castSafeStrings($value);
|
||||
// The dot/period is a reserved character; it may appear between keys, but
|
||||
// not within keys.
|
||||
if (is_array($value)) {
|
||||
|
@ -280,4 +277,27 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
return $this->cacheMaxAge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts any objects that implement MarkupInterface to string.
|
||||
*
|
||||
* @param mixed $data
|
||||
* The configuration data.
|
||||
*
|
||||
* @return mixed
|
||||
* The data with any safe strings cast to string.
|
||||
*/
|
||||
protected function castSafeStrings($data) {
|
||||
if ($data instanceof MarkupInterface) {
|
||||
$data = (string) $data;
|
||||
}
|
||||
else if (is_array($data)) {
|
||||
array_walk_recursive($data, function (&$value) {
|
||||
if ($value instanceof MarkupInterface) {
|
||||
$value = (string) $value;
|
||||
}
|
||||
});
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -367,8 +367,8 @@ class ConfigImporter {
|
|||
$current_extensions = $this->storageComparer->getTargetStorage()->read('core.extension');
|
||||
$new_extensions = $this->storageComparer->getSourceStorage()->read('core.extension');
|
||||
|
||||
// If there is no extension information in staging then exit. This is
|
||||
// probably due to an empty staging directory.
|
||||
// If there is no extension information in sync then exit. This is probably
|
||||
// due to an empty sync directory.
|
||||
if (!$new_extensions) {
|
||||
return;
|
||||
}
|
||||
|
@ -718,11 +718,11 @@ class ConfigImporter {
|
|||
$old_entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']);
|
||||
$new_entity_type_id = $this->configManager->getEntityTypeIdByName($names['new_name']);
|
||||
if ($old_entity_type_id != $new_entity_type_id) {
|
||||
$this->logError($this->t('Entity type mismatch on rename. !old_type not equal to !new_type for existing configuration !old_name and staged configuration !new_name.', array('old_type' => $old_entity_type_id, 'new_type' => $new_entity_type_id, 'old_name' => $names['old_name'], 'new_name' => $names['new_name'])));
|
||||
$this->logError($this->t('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => $old_entity_type_id, '@new_type' => $new_entity_type_id, '@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
|
||||
}
|
||||
// Has to be a configuration entity.
|
||||
if (!$old_entity_type_id) {
|
||||
$this->logError($this->t('Rename operation for simple configuration. Existing configuration !old_name and staged configuration !new_name.', array('old_name' => $names['old_name'], 'new_name' => $names['new_name'])));
|
||||
$this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array('@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
|
||||
}
|
||||
}
|
||||
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
|
||||
|
@ -762,7 +762,7 @@ class ConfigImporter {
|
|||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->logError($this->t('Unexpected error during import with operation @op for @name: !message', array('@op' => $op, '@name' => $name, '!message' => $e->getMessage())));
|
||||
$this->logError($this->t('Unexpected error during import with operation @op for @name: @message', array('@op' => $op, '@name' => $name, '@message' => $e->getMessage())));
|
||||
// Error for that operation was logged, mark it as processed so that
|
||||
// the import can continue.
|
||||
$this->setProcessedConfiguration($collection, $op, $name);
|
||||
|
@ -780,7 +780,7 @@ class ConfigImporter {
|
|||
* The name of the extension to process.
|
||||
*/
|
||||
protected function processExtension($type, $op, $name) {
|
||||
// Set the config installer to use the staging directory instead of the
|
||||
// Set the config installer to use the sync directory instead of the
|
||||
// extensions own default config directories.
|
||||
\Drupal::service('config.installer')
|
||||
->setSyncing(TRUE)
|
||||
|
|
|
@ -155,11 +155,15 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
// Check for new or removed files.
|
||||
if ($source_data === array('false')) {
|
||||
// Added file.
|
||||
$source_data = array($this->t('File added'));
|
||||
// Cast the result of t() to a string, as the diff engine doesn't know
|
||||
// about objects.
|
||||
$source_data = array((string) $this->t('File added'));
|
||||
}
|
||||
if ($target_data === array('false')) {
|
||||
// Deleted file.
|
||||
$target_data = array($this->t('File removed'));
|
||||
// Cast the result of t() to a string, as the diff engine doesn't know
|
||||
// about objects.
|
||||
$target_data = array((string) $this->t('File removed'));
|
||||
}
|
||||
|
||||
return new Diff($source_data, $target_data);
|
||||
|
@ -316,7 +320,8 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
}
|
||||
if ($this->callOnDependencyRemoval($dependent, $original_dependencies, $type, $names)) {
|
||||
// Recalculate dependencies and update the dependency graph data.
|
||||
$dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->calculateDependencies());
|
||||
$dependent->calculateDependencies();
|
||||
$dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->getDependencies());
|
||||
// Based on the updated data rebuild the list of dependents.
|
||||
$dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager);
|
||||
// Ensure that the dependency has actually been fixed. It is possible
|
||||
|
@ -454,6 +459,9 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
if (isset($config_data['dependencies']['content'])) {
|
||||
$content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
|
||||
}
|
||||
if (isset($config_data['dependencies']['enforced']['content'])) {
|
||||
$content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['enforced']['content']);
|
||||
}
|
||||
}
|
||||
foreach (array_unique($content_dependencies) as $content_dependency) {
|
||||
// Format of the dependency is entity_type:bundle:uuid.
|
||||
|
|
|
@ -53,8 +53,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
'#type' => 'details',
|
||||
'#title' => $this->t('Configuration updates'),
|
||||
'#description' => $this->t('The listed configuration will be updated.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#open' => TRUE,
|
||||
'#access' => FALSE,
|
||||
);
|
||||
|
||||
|
@ -72,7 +71,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
'#items' => array(),
|
||||
);
|
||||
}
|
||||
$form['entity_updates'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id();
|
||||
$form['entity_updates'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
|
||||
}
|
||||
if (!empty($dependent_entities['update'])) {
|
||||
$form['entity_updates']['#access'] = TRUE;
|
||||
|
@ -83,7 +82,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
foreach ($entity_types as $entity_type_id => $label) {
|
||||
$form['entity_updates'][$entity_type_id]['#weight'] = $weight;
|
||||
// Sort the list of entity labels alphabetically.
|
||||
sort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE);
|
||||
ksort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE);
|
||||
$weight++;
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +91,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
'#type' => 'details',
|
||||
'#title' => $this->t('Configuration deletions'),
|
||||
'#description' => $this->t('The listed configuration will be deleted.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#open' => TRUE,
|
||||
'#access' => FALSE,
|
||||
);
|
||||
|
||||
|
@ -110,7 +108,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
'#items' => array(),
|
||||
);
|
||||
}
|
||||
$form['entity_deletes'][$entity_type_id]['#items'][] = $entity->label() ?: $entity->id();
|
||||
$form['entity_deletes'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
|
||||
}
|
||||
if (!empty($dependent_entities['delete'])) {
|
||||
$form['entity_deletes']['#access'] = TRUE;
|
||||
|
@ -119,10 +117,12 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
asort($entity_types, SORT_FLAG_CASE);
|
||||
$weight = 0;
|
||||
foreach ($entity_types as $entity_type_id => $label) {
|
||||
$form['entity_deletes'][$entity_type_id]['#weight'] = $weight;
|
||||
// Sort the list of entity labels alphabetically.
|
||||
sort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE);
|
||||
$weight++;
|
||||
if (isset($form['entity_deletes'][$entity_type_id])) {
|
||||
$form['entity_deletes'][$entity_type_id]['#weight'] = $weight;
|
||||
// Sort the list of entity labels alphabetically.
|
||||
ksort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE);
|
||||
$weight++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,11 @@ use Drupal\Component\Utility\SortArray;
|
|||
* Configuration entity classes usually extend
|
||||
* \Drupal\Core\Config\Entity\ConfigEntityBase. The base class provides a
|
||||
* generic implementation of the calculateDependencies() method that can
|
||||
* discover dependencies due to enforced dependencies, plugins, and third party
|
||||
* settings. If the configuration entity has dependencies that cannot be
|
||||
* discovered by the base class's implementation, then it needs to implement
|
||||
* discover dependencies due to plugins, and third party settings. If the
|
||||
* configuration entity has dependencies that cannot be discovered by the base
|
||||
* class's implementation, then it needs to implement
|
||||
* \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() to
|
||||
* calculate (and return) the dependencies. In this method, use
|
||||
* calculate the dependencies. In this method, use
|
||||
* \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency() to add
|
||||
* dependencies. Implementations should call the base class implementation to
|
||||
* inherit the generic functionality.
|
||||
|
@ -85,9 +85,9 @@ use Drupal\Component\Utility\SortArray;
|
|||
* configuration object so that they can be checked without the module that
|
||||
* provides the configuration entity class being installed. This is important
|
||||
* for configuration synchronization, which needs to be able to validate
|
||||
* configuration in the staging directory before the synchronization has
|
||||
* occurred. Also, if you have a configuration entity object and you want to
|
||||
* get the current dependencies without recalculation, you can use
|
||||
* configuration in the sync directory before the synchronization has occurred.
|
||||
* Also, if you have a configuration entity object and you want to get the
|
||||
* current dependencies (without recalculation), you can use
|
||||
* \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies().
|
||||
*
|
||||
* When uninstalling a module or a theme, configuration entities that are
|
||||
|
@ -115,6 +115,7 @@ use Drupal\Component\Utility\SortArray;
|
|||
* module dependency in the sub-module only.
|
||||
*
|
||||
* @see \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies()
|
||||
* @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies()
|
||||
* @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval()
|
||||
* @see \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency()
|
||||
* @see \Drupal\Core\Config\ConfigInstallerInterface::installDefaultConfig()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Config\Entity;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Config\ConfigException;
|
||||
use Drupal\Core\Config\Schema\SchemaIncompleteException;
|
||||
|
@ -341,7 +342,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this entity already exists with UUID '{$original->uuid()}'");
|
||||
}
|
||||
}
|
||||
if (!$this->isSyncing() && !$this->trustedData) {
|
||||
if (!$this->isSyncing()) {
|
||||
// Ensure the correct dependencies are present. If the configuration is
|
||||
// being written during a configuration synchronization then there is no
|
||||
// need to recalculate the dependencies.
|
||||
|
@ -353,16 +354,9 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
// Dependencies should be recalculated on every save. This ensures stale
|
||||
// dependencies are never saved.
|
||||
if (isset($this->dependencies['enforced'])) {
|
||||
$dependencies = $this->dependencies['enforced'];
|
||||
$this->dependencies = $dependencies;
|
||||
$this->dependencies['enforced'] = $dependencies;
|
||||
}
|
||||
else {
|
||||
$this->dependencies = array();
|
||||
}
|
||||
// All dependencies should be recalculated on every save apart from enforced
|
||||
// dependencies. This ensures stale dependencies are never saved.
|
||||
$this->dependencies = array_intersect_key($this->dependencies, ['enforced' => '']);
|
||||
if ($this instanceof EntityWithPluginCollectionInterface) {
|
||||
// Configuration entities need to depend on the providers of any plugins
|
||||
// that they store the configuration for.
|
||||
|
@ -379,13 +373,15 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
$this->addDependency('module', $provider);
|
||||
}
|
||||
}
|
||||
return $this->dependencies;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function urlInfo($rel = 'edit-form', array $options = []) {
|
||||
// Unless language was already provided, avoid setting an explicit language.
|
||||
$options += ['language' => NULL];
|
||||
return parent::urlInfo($rel, $options);
|
||||
}
|
||||
|
||||
|
@ -436,7 +432,14 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDependencies() {
|
||||
return $this->dependencies;
|
||||
$dependencies = $this->dependencies;
|
||||
if (isset($dependencies['enforced'])) {
|
||||
// Merge the enforced dependencies into the list of dependencies.
|
||||
$enforced_dependencies = $dependencies['enforced'];
|
||||
unset($dependencies['enforced']);
|
||||
$dependencies = NestedArray::mergeDeep($dependencies, $enforced_dependencies);
|
||||
}
|
||||
return $dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Config\Entity;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\Core\Config\ConfigNameException;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
|
||||
/**
|
||||
|
@ -19,31 +18,6 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
*/
|
||||
abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
||||
|
||||
/**
|
||||
* Renames displays when a bundle is renamed.
|
||||
*/
|
||||
protected function renameDisplays() {
|
||||
// Rename entity displays.
|
||||
if ($this->getOriginalId() !== $this->id()) {
|
||||
foreach ($this->loadDisplays('entity_view_display') as $display) {
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->getMode();
|
||||
$display->set('id', $new_id);
|
||||
$display->setTargetBundle($this->id());
|
||||
$display->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Rename entity form displays.
|
||||
if ($this->getOriginalId() !== $this->id()) {
|
||||
foreach ($this->loadDisplays('entity_form_display') as $form_display) {
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->getMode();
|
||||
$form_display->set('id', $new_id);
|
||||
$form_display->setTargetBundle($this->id());
|
||||
$form_display->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes display if a bundle is deleted.
|
||||
*/
|
||||
|
@ -80,12 +54,6 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
|||
}
|
||||
// Entity bundle field definitions may depend on bundle settings.
|
||||
$entity_manager->clearCachedFieldDefinitions();
|
||||
|
||||
if ($this->getOriginalId() != $this->id()) {
|
||||
// If the entity was renamed, update the displays.
|
||||
$this->renameDisplays();
|
||||
$entity_manager->onBundleRename($this->getOriginalId(), $this->id(), $bundle_of);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,6 +69,33 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts on an entity before the presave hook is invoked.
|
||||
*
|
||||
* Used before the entity is saved and before invoking the presave hook.
|
||||
*
|
||||
* Ensure that config entities which are bundles of other entities cannot have
|
||||
* their ID changed.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
|
||||
* The entity storage object.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\ConfigNameException
|
||||
* Thrown when attempting to rename a bundle entity.
|
||||
*/
|
||||
public function preSave(EntityStorageInterface $storage) {
|
||||
parent::preSave($storage);
|
||||
|
||||
// Only handle renames, not creations.
|
||||
if (!$this->isNew() && $this->getOriginalId() !== $this->id()) {
|
||||
$bundle_type = $this->getEntityType();
|
||||
$bundle_of = $bundle_type->getBundleOf();
|
||||
if (!empty($bundle_of)) {
|
||||
throw new ConfigNameException("The machine name of the '{$bundle_type->getLabel()}' bundle cannot be changed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view or form displays for this bundle.
|
||||
*
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\Core\Config\Entity;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
|
||||
/**
|
||||
* Provides a value object to discover configuration dependencies.
|
||||
*
|
||||
|
@ -26,7 +28,7 @@ class ConfigEntityDependency {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dependencies;
|
||||
protected $dependencies = [];
|
||||
|
||||
/**
|
||||
* Constructs the configuration entity dependency from the entity values.
|
||||
|
@ -36,13 +38,16 @@ class ConfigEntityDependency {
|
|||
* @param array $values
|
||||
* (optional) The configuration entity's values.
|
||||
*/
|
||||
public function __construct($name, $values = array()) {
|
||||
public function __construct($name, $values = []) {
|
||||
$this->name = $name;
|
||||
if (isset($values['dependencies'])) {
|
||||
$this->dependencies = $values['dependencies'];
|
||||
if (isset($values['dependencies']) && isset($values['dependencies']['enforced'])) {
|
||||
// Merge the enforced dependencies into the list of dependencies.
|
||||
$enforced_dependencies = $values['dependencies']['enforced'];
|
||||
unset($values['dependencies']['enforced']);
|
||||
$this->dependencies = NestedArray::mergeDeep($values['dependencies'], $enforced_dependencies);
|
||||
}
|
||||
else {
|
||||
$this->dependencies = array();
|
||||
elseif (isset($values['dependencies'])) {
|
||||
$this->dependencies = $values['dependencies'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,8 +144,7 @@ interface ConfigEntityInterface extends EntityInterface, ThirdPartySettingsInter
|
|||
/**
|
||||
* Calculates dependencies and stores them in the dependency property.
|
||||
*
|
||||
* @return array
|
||||
* An array of dependencies grouped by type (module, theme, entity).
|
||||
* @return $this
|
||||
*
|
||||
* @see \Drupal\Core\Config\Entity\ConfigDependencyManager
|
||||
*/
|
||||
|
|
|
@ -16,18 +16,21 @@ class FileStorageFactory {
|
|||
* Returns a FileStorage object working with the active config directory.
|
||||
*
|
||||
* @return \Drupal\Core\Config\FileStorage FileStorage
|
||||
*
|
||||
* @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core
|
||||
* no longer creates an active directory.
|
||||
*/
|
||||
static function getActive() {
|
||||
return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FileStorage object working with the staging config directory.
|
||||
* Returns a FileStorage object working with the sync config directory.
|
||||
*
|
||||
* @return \Drupal\Core\Config\FileStorage FileStorage
|
||||
*/
|
||||
static function getStaging() {
|
||||
return new FileStorage(config_get_config_directory(CONFIG_STAGING_DIRECTORY));
|
||||
static function getSync() {
|
||||
return new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,27 +7,10 @@
|
|||
|
||||
namespace Drupal\Core\Config\Schema;
|
||||
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Drupal\Core\TypedData\TypedData;
|
||||
|
||||
/**
|
||||
* Defines a generic configuration element that contains multiple properties.
|
||||
*/
|
||||
abstract class ArrayElement extends TypedData implements \IteratorAggregate, TypedConfigInterface {
|
||||
|
||||
/**
|
||||
* The typed config manager.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface
|
||||
*/
|
||||
protected $typedConfig;
|
||||
|
||||
/**
|
||||
* The configuration value.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
abstract class ArrayElement extends Element implements \IteratorAggregate, TypedConfigInterface {
|
||||
|
||||
/**
|
||||
* Parsed elements.
|
||||
|
@ -152,7 +135,7 @@ abstract class ArrayElement extends TypedData implements \IteratorAggregate, Typ
|
|||
* @return \Drupal\Core\TypedData\TypedDataInterface
|
||||
*/
|
||||
protected function createElement($definition, $value, $key) {
|
||||
return $this->typedConfig->create($definition, $value, $key, $this);
|
||||
return $this->getTypedDataManager()->create($definition, $value, $key, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,20 +153,17 @@ abstract class ArrayElement extends TypedData implements \IteratorAggregate, Typ
|
|||
* @return \Drupal\Core\TypedData\DataDefinitionInterface
|
||||
*/
|
||||
protected function buildDataDefinition($definition, $value, $key) {
|
||||
return $this->typedConfig->buildDataDefinition($definition, $value, $key, $this);
|
||||
return $this->getTypedDataManager()->buildDataDefinition($definition, $value, $key, $this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the typed config manager on the instance.
|
||||
* Determines if this element allows NULL as a value.
|
||||
*
|
||||
* This must be called immediately after construction to enable
|
||||
* self::parseElement() and self::buildDataDefinition() to work.
|
||||
*
|
||||
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
|
||||
* @return bool
|
||||
* TRUE if NULL is a valid value, FALSE otherwise.
|
||||
*/
|
||||
public function setTypedConfig(TypedConfigManagerInterface $typed_config) {
|
||||
$this->typedConfig = $typed_config;
|
||||
public function isNullable() {
|
||||
return isset($this->definition['nullable']) && $this->definition['nullable'] == TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
namespace Drupal\Core\Config\Schema;
|
||||
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Drupal\Core\TypedData\TypedData;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
|
||||
/**
|
||||
* Defines a generic configuration element.
|
||||
|
@ -21,4 +23,41 @@ abstract class Element extends TypedData {
|
|||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* Gets the typed configuration manager.
|
||||
*
|
||||
* Overrides \Drupal\Core\TypedData\TypedDataTrait::getTypedDataManager() to
|
||||
* ensure the typed configuration manager is returned.
|
||||
*
|
||||
* @return \Drupal\Core\Config\TypedConfigManagerInterface
|
||||
* The typed configuration manager.
|
||||
*/
|
||||
public function getTypedDataManager() {
|
||||
if (empty($this->typedDataManager)) {
|
||||
$this->setTypedDataManager(\Drupal::service('config.typed'));
|
||||
}
|
||||
|
||||
return $this->typedDataManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the typed config manager.
|
||||
*
|
||||
* Overrides \Drupal\Core\TypedData\TypedDataTrait::setTypedDataManager() to
|
||||
* ensure that only typed configuration manager can be used.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
|
||||
* The typed config manager. This must be an instance of
|
||||
* \Drupal\Core\Config\TypedConfigManagerInterface. If it is not, then this
|
||||
* method will error when assertions are enabled. We can not narrow the
|
||||
* typehint as this will cause PHP errors.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTypedDataManager(TypedDataManagerInterface $typed_data_manager) {
|
||||
assert($typed_data_manager instanceof TypedConfigManagerInterface, '$typed_data_manager should be an instance of \Drupal\Core\Config\TypedConfigManagerInterface.');
|
||||
$this->typedDataManager = $typed_data_manager;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -106,9 +106,13 @@ trait SchemaCheckTrait {
|
|||
(($type == 'double' || $type == 'integer') && $element instanceof FloatInterface) ||
|
||||
($type == 'boolean' && $element instanceof BooleanInterface) ||
|
||||
($type == 'string' && $element instanceof StringInterface) ||
|
||||
// Null values are allowed for all types.
|
||||
// Null values are allowed for all primitive types.
|
||||
($value === NULL);
|
||||
}
|
||||
// Array elements can also opt-in for allowing a NULL value.
|
||||
elseif ($element instanceof ArrayElement && $element->isNullable() && $value === NULL) {
|
||||
$success = TRUE;
|
||||
}
|
||||
$class = get_class($element);
|
||||
if (!$success) {
|
||||
return array($error_key => "variable type is $type but applied schema class is $class");
|
||||
|
|
|
@ -98,7 +98,7 @@ abstract class StorableConfigBase extends ConfigBase {
|
|||
*/
|
||||
public function initWithData(array $data) {
|
||||
$this->isNew = FALSE;
|
||||
$this->setData($data, FALSE);
|
||||
$this->data = $data;
|
||||
$this->originalData = $this->data;
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -71,13 +71,7 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
|
|||
|
||||
|
||||
/**
|
||||
* Gets typed configuration data.
|
||||
*
|
||||
* @param string $name
|
||||
* Configuration object name.
|
||||
*
|
||||
* @return \Drupal\Core\Config\Schema\TypedConfigInterface
|
||||
* Typed configuration data.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($name) {
|
||||
$data = $this->configStorage->read($name);
|
||||
|
@ -282,8 +276,12 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
|
|||
return $value;
|
||||
}
|
||||
elseif (!$parts) {
|
||||
$value = $data[$name];
|
||||
if (is_bool($value)) {
|
||||
$value = (int) $value;
|
||||
}
|
||||
// If no more parts left, this is the final property.
|
||||
return (string)$data[$name];
|
||||
return (string) $value;
|
||||
}
|
||||
else {
|
||||
// Get nested value and continue processing.
|
||||
|
@ -338,17 +336,4 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($data_type, array $configuration = array()) {
|
||||
$instance = parent::createInstance($data_type, $configuration);
|
||||
// Enable elements to construct their own definitions using the typed config
|
||||
// manager.
|
||||
if ($instance instanceof ArrayElement) {
|
||||
$instance->setTypedConfig($this);
|
||||
}
|
||||
return $instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Config;
|
||||
|
||||
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
|
||||
use Drupal\Component\Plugin\PluginManagerInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\TypedDataManagerInterface;
|
||||
|
||||
/**
|
||||
* Defines an interface for managing config schema type plugins.
|
||||
|
@ -19,7 +17,7 @@ use Drupal\Core\TypedData\DataDefinitionInterface;
|
|||
* @see hook_config_schema_info_alter()
|
||||
* @see https://www.drupal.org/node/1905070
|
||||
*/
|
||||
Interface TypedConfigManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface {
|
||||
Interface TypedConfigManagerInterface extends TypedDataManagerInterface {
|
||||
|
||||
/**
|
||||
* Gets typed configuration data.
|
||||
|
@ -32,48 +30,6 @@ Interface TypedConfigManagerInterface extends PluginManagerInterface, CachedDisc
|
|||
*/
|
||||
public function get($name);
|
||||
|
||||
/**
|
||||
* Instantiates a typed configuration object.
|
||||
*
|
||||
* @param string $data_type
|
||||
* The data type, for which a typed configuration object should be
|
||||
* instantiated.
|
||||
* @param array $configuration
|
||||
* The plugin configuration array, i.e. an array with the following keys:
|
||||
* - data definition: The data definition object, i.e. an instance of
|
||||
* \Drupal\Core\TypedData\DataDefinitionInterface.
|
||||
* - name: (optional) If a property or list item is to be created, the name
|
||||
* of the property or the delta of the list item.
|
||||
* - parent: (optional) If a property or list item is to be created, the
|
||||
* parent typed data object implementing either the ListInterface or the
|
||||
* ComplexDataInterface.
|
||||
*
|
||||
* @return \Drupal\Core\Config\Schema\Element
|
||||
* The instantiated typed configuration object.
|
||||
*/
|
||||
public function createInstance($data_type, array $configuration = array());
|
||||
|
||||
/**
|
||||
* Creates a new typed configuration object instance.
|
||||
*
|
||||
* @param \Drupal\Core\TypedData\DataDefinitionInterface $definition
|
||||
* The data definition of the typed data object.
|
||||
* @param mixed $value
|
||||
* The data value. If set, it has to match one of the supported
|
||||
* data type format as documented for the data type classes.
|
||||
* @param string $name
|
||||
* (optional) If a property or list item is to be created, the name of the
|
||||
* property or the delta of the list item.
|
||||
* @param mixed $parent
|
||||
* (optional) If a property or list item is to be created, the parent typed
|
||||
* data object implementing either the ListInterface or the
|
||||
* ComplexDataInterface.
|
||||
*
|
||||
* @return \Drupal\Core\Config\Schema\Element
|
||||
* The instantiated typed data object.
|
||||
*/
|
||||
public function create(DataDefinitionInterface $definition, $value, $name = NULL, $parent = NULL);
|
||||
|
||||
/**
|
||||
* Creates a new data definition object from a type definition array and
|
||||
* actual configuration data. Since type definitions may contain variables
|
||||
|
|
Reference in a new issue