本文整理汇总了PHP中Drupal\Core\Config\StorageInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface类的具体用法?PHP StorageInterface怎么用?PHP StorageInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StorageInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copyConfig
/**
* Copies configuration objects from source storage to target storage.
*
* @param \Drupal\Core\Config\StorageInterface $source_storage
* The source config storage service.
* @param \Drupal\Core\Config\StorageInterface $target_storage
* The target config storage service.
*/
protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage)
{
$target_storage->deleteAll();
foreach ($source_storage->listAll() as $name) {
$target_storage->write($name, $source_storage->read($name));
}
}
示例2: filterWrite
public function filterWrite($name, array $data, StorageInterface $storage)
{
if ($name != 'core.extension') {
return $data;
}
$originalData = $storage->read($name);
return $this->filterOutIgnored($data, $storage->read($name));
}
示例3: filterWrite
public function filterWrite($name, array $data, StorageInterface $storage)
{
if ($name == 'core.extension') {
return $this->filterOutIgnored($data, $storage->read($name));
}
$dependent_configs = $this->getAllDependentConfigs($storage);
if (in_array($name, $dependent_configs)) {
$data = ($existing = $storage->read($name)) ? $existing : NULL;
}
return $data;
}
示例4: getActiveStorage
/**
* Gets the configuration storage that provides the active configuration.
*
* @param string $collection
* (optional) The configuration collection. Defaults to the default
* collection.
*
* @return \Drupal\Core\Config\StorageInterface
* The configuration storage that provides the default configuration.
*/
protected function getActiveStorage($collection = StorageInterface::DEFAULT_COLLECTION)
{
if ($this->activeStorage->getCollectionName() != $collection) {
$this->activeStorage = $this->activeStorage->createCollection($collection);
}
return $this->activeStorage;
}
示例5: getCollectionPrefix
/**
* Returns a cache ID prefix to use for the collection.
*
* @return string
* The cache ID prefix.
*/
protected function getCollectionPrefix()
{
$collection = $this->storage->getCollectionName();
if ($collection == StorageInterface::DEFAULT_COLLECTION) {
return '';
}
return $collection . ':';
}
示例6: getAllCollectionNames
/**
* {@inheritdoc}
*/
public function getAllCollectionNames($include_default = TRUE)
{
$collections = array_unique(array_merge($this->sourceStorage->getAllCollectionNames(), $this->targetStorage->getAllCollectionNames()));
if ($include_default) {
array_unshift($collections, StorageInterface::DEFAULT_COLLECTION);
}
return $collections;
}
示例7: loadOverrides
/**
* {@inheritdoc}
*/
public function loadOverrides($names)
{
$overrides = array();
// loadOverrides() runs on config entities, which means that if we try
// to run this routine on our own data, then we end up in an infinite loop.
// So ensure that we are _not_ looking up a domain.record.*.
$check = current($names);
$list = explode('.', $check);
if (isset($list[0]) && isset($list[1]) && $list[0] == 'domain' && $list[1] == 'record') {
return $overrides;
}
$this->initiateContext();
if (!empty($this->domain)) {
foreach ($names as $name) {
$config_name = $this->getDomainConfigName($name, $this->domain);
// Check to see if the config storage has an appropriately named file
// containing override data.
if ($override = $this->storage->read($config_name['langcode'])) {
$overrides[$name] = $override;
} elseif ($override = $this->storage->read($config_name['domain'])) {
$overrides[$name] = $override;
}
}
}
return $overrides;
}
示例8: getConfigNames
protected function getConfigNames($config_type)
{
$this->configStorage = $this->getDrupalService('config.storage');
// For a given entity type, load all entities.
if ($config_type && $config_type !== 'system.simple') {
$entity_storage = $this->entityManager->getStorage($config_type);
foreach ($entity_storage->loadMultiple() as $entity) {
$entity_id = $entity->id();
$label = $entity->label() ?: $entity_id;
$names[$entity_id] = $label;
}
} else {
// Gather the config entity prefixes.
$config_prefixes = array_map(function ($definition) {
return $definition->getConfigPrefix() . '.';
}, $this->definitions);
// Find all config, and then filter our anything matching a config prefix.
$names = $this->configStorage->listAll();
$names = array_combine($names, $names);
foreach ($names as $config_name) {
foreach ($config_prefixes as $config_prefix) {
if (strpos($config_name, $config_prefix) === 0) {
unset($names[$config_name]);
}
}
}
}
return $names;
}
示例9: getAllFolders
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getComponentNames('core', array('core'));
$extensions = $this->configStorage->read('core.extension');
if (!empty($extensions['module'])) {
$modules = $extensions['module'];
if (!$this->includeProfile) {
if ($install_profile = Settings::get('install_profile')) {
unset($modules[$install_profile]);
}
}
$this->folders += $this->getComponentNames('module', array_keys($modules));
}
if (!empty($extensions['theme'])) {
$this->folders += $this->getComponentNames('theme', array_keys($extensions['theme']));
}
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
$profile_folders = $this->getComponentNames('profile', array(drupal_get_profile()));
$folders_to_replace = array_intersect_key($profile_folders, $this->folders);
if (!empty($folders_to_replace)) {
$this->folders = array_merge($this->folders, $folders_to_replace);
}
}
return $this->folders;
}
示例10: testRename
/**
* @covers ::rename
*/
public function testRename()
{
$old = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
$new = new Config($this->randomMachineName(), $this->storage, $this->eventDispatcher, $this->typedConfig);
$this->storage->expects($this->exactly(2))->method('readMultiple')->willReturnMap([[[$old->getName()], $old->getRawData()], [[$new->getName()], $new->getRawData()]]);
$this->cacheTagsInvalidator->expects($this->once())->method('invalidateTags')->with($old->getCacheTags());
$this->storage->expects($this->once())->method('rename')->with($old->getName(), $new->getName());
$this->configFactory->rename($old->getName(), $new->getName());
}
示例11: getAllFolders
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getCoreNames();
$install_profile = Settings::get('install_profile');
$profile = drupal_get_profile();
$extensions = $this->configStorage->read('core.extension');
// @todo Remove this scan as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root());
if (!empty($extensions['module'])) {
$modules = $extensions['module'];
// Remove the install profile as this is handled later.
unset($modules[$install_profile]);
$profile_list = $listing->scan('profile');
if ($profile && isset($profile_list[$profile])) {
// Prime the drupal_get_filename() static cache with the profile info
// file location so we can use drupal_get_path() on the active profile
// during the module scan.
// @todo Remove as part of https://www.drupal.org/node/2186491
drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname());
}
$module_list_scan = $listing->scan('module');
$module_list = array();
foreach (array_keys($modules) as $module) {
if (isset($module_list_scan[$module])) {
$module_list[$module] = $module_list_scan[$module];
}
}
$this->folders += $this->getComponentNames($module_list);
}
if (!empty($extensions['theme'])) {
$theme_list_scan = $listing->scan('theme');
foreach (array_keys($extensions['theme']) as $theme) {
if (isset($theme_list_scan[$theme])) {
$theme_list[$theme] = $theme_list_scan[$theme];
}
}
$this->folders += $this->getComponentNames($theme_list);
}
if ($this->includeProfile) {
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
if (isset($profile)) {
if (!isset($profile_list)) {
$profile_list = $listing->scan('profile');
}
if (isset($profile_list[$profile])) {
$profile_folders = $this->getComponentNames(array($profile_list[$profile]));
$this->folders = $profile_folders + $this->folders;
}
}
}
}
return $this->folders;
}
示例12: getDefinitions
/**
* {@inheritdoc}
*/
public function getDefinitions()
{
$definitions = array();
foreach ($this->schemaStorage->readMultiple($this->schemaStorage->listAll()) as $schema) {
foreach ($schema as $type => $definition) {
$definitions[$type] = $definition;
}
}
return $definitions;
}
示例13: findConfiguration
/**
* Handles switching the configuration type selector.
*/
protected function findConfiguration($config_type)
{
$names = array('' => $this->t('- Select -'));
// For a given entity type, load all entities.
if ($config_type && $config_type !== 'system.simple') {
$entity_storage = $this->entityManager->getStorage($config_type);
foreach ($entity_storage->loadMultiple() as $entity) {
$entity_id = $entity->id();
if ($label = $entity->label()) {
$names[$entity_id] = new TranslatableMarkup('@label (@id)', ['@label' => $label, '@id' => $entity_id]);
} else {
$names[$entity_id] = $entity_id;
}
}
} else {
// Gather the config entity prefixes.
$config_prefixes = array_map(function (EntityTypeInterface $definition) {
return $definition->getConfigPrefix() . '.';
}, $this->definitions);
// Find all config, and then filter our anything matching a config prefix.
$names = $this->configStorage->listAll();
$names = array_combine($names, $names);
foreach ($names as $config_name) {
foreach ($config_prefixes as $config_prefix) {
if (strpos($config_name, $config_prefix) === 0) {
unset($names[$config_name]);
}
}
}
}
return $names;
}
示例14: getStorage
/**
* {@inheritdoc}
*/
public function getStorage($langcode)
{
if (!isset($this->storages[$langcode])) {
$this->storages[$langcode] = $this->baseStorage->createCollection($this->createConfigCollectionName($langcode));
}
return $this->storages[$langcode];
}
示例15: getFromExtension
/**
* {@inheritdoc}
*/
public function getFromExtension($type, $name)
{
$full_name = $this->getFullName($type, $name);
$value = $this->extensionConfigStorage->read($full_name);
if (!$value) {
$value = $this->extensionOptionalConfigStorage->read($full_name);
}
return $value;
}