作者:eigento
项目:tommiblo
/**
* 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));
}
}
作者:bjargu
项目:drus
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));
}
作者:gael
项目:drus
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;
}
作者:anatalsce
项目:en-class
/**
* 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;
}
作者:davidsoloma
项目:drupalconsole.co
/**
* 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 . ':';
}
作者:nstiela
项目:drops-
/**
* {@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;
}
作者:dropdo
项目:pla
/**
* {@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;
}
作者:mnic
项目:DrupalConsol
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;
}
作者:davidsoloma
项目:drupalconsole.co
/**
* 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;
}
作者:aWEBoLab
项目:tax
/**
* @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());
}
作者:ravibarnwa
项目:laraitassociate.i
/**
* 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;
}
作者:ddrozdi
项目:dmap
/**
* {@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;
}
作者:318i
项目:318-i
/**
* 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;
}
作者:anatalsce
项目:en-class
/**
* {@inheritdoc}
*/
public function getStorage($langcode)
{
if (!isset($this->storages[$langcode])) {
$this->storages[$langcode] = $this->baseStorage->createCollection($this->createConfigCollectionName($langcode));
}
return $this->storages[$langcode];
}
作者:curveagenc
项目:intrane
/**
* {@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;
}
作者:davidsoloma
项目:drupalconsole.co
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($path = $form_state->getValue('import_tarball')) {
$this->configStorage->deleteAll();
try {
$archiver = new ArchiveTar($path, 'gz');
$files = array();
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY));
drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.'));
$form_state->setRedirect('config.sync');
} catch (\Exception $e) {
drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
}
drupal_unlink($path);
}
}
作者:nishantkumar15
项目:drupal8.crackl
/**
* @covers ::importCurrencyLocale
*/
public function testImportCurrencyLocaleWithExistingCurrency()
{
$locale = $this->randomMachineName();
$currency_locale = $this->getMock(CurrencyLocaleInterface::class);
$this->currencyLocaleStorage->expects($this->never())->method('create');
$this->currencyLocaleStorage->expects($this->once())->method('load')->with($locale)->willReturn($currency_locale);
$this->configStorage->expects($this->never())->method('read');
$this->sut->setConfigStorage($this->configStorage);
$this->assertFalse($this->sut->importCurrencyLocale($locale));
}
作者:ddrozdi
项目:dmap
/**
* Test the import subscriber.
*/
public function testSubscribers()
{
// Without this the config exporter breaks.
\Drupal::service('config.installer')->installDefaultConfig('module', 'config_devel');
$filename = vfsStream::url('public://' . static::CONFIGNAME . '.yml');
drupal_mkdir(vfsStream::url('public://exported'));
$exported_filename = vfsStream::url('public://exported/' . static::CONFIGNAME . '.yml');
\Drupal::configFactory()->getEditable('config_devel.settings')->set('auto_import', array(array('filename' => $filename, 'hash' => '')))->set('auto_export', array($exported_filename))->save();
$this->storage = \Drupal::service('config.storage');
$this->assertFalse($this->storage->exists(static::CONFIGNAME));
$subscriber = \Drupal::service('config_devel.auto_import_subscriber');
for ($i = 2; $i; $i--) {
$data['label'] = $this->randomString();
file_put_contents($filename, Yaml::encode($data));
// The import fires an export too.
$subscriber->autoImportConfig();
$this->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
}
}
作者:jeetendrasing
项目:manage_profil
protected function addConfigList($full_name, &$list) {
if (!in_array($full_name, $list)) {
array_unshift($list, $full_name);
$value = $this->extensionStorage->read($full_name);
if (isset($value['dependencies']['config'])) {
foreach ($value['dependencies']['config'] as $config_name) {
$this->addConfigList($config_name, $list);
}
}
}
}
作者:sarahwille
项目:OD
/**
* Compute the list of configuration names that match predefined languages.
*
* @return array
* The list of configuration names that match predefined languages.
*/
protected function predefinedConfiguredLanguages()
{
$names = $this->configStorage->listAll('language.entity.');
$predefined_languages = $this->languageManager->getStandardLanguageList();
foreach ($names as $id => $name) {
$langcode = str_replace('language.entity.', '', $name);
if (!isset($predefined_languages[$langcode])) {
unset($names[$id]);
}
}
return array_values($names);
}