2011-06-10 01:13:07 +00:00
|
|
|
<?php
|
|
|
|
|
2013-09-13 09:31:12 +00:00
|
|
|
use Drupal\Component\Utility\Unicode;
|
2012-07-03 21:03:18 +00:00
|
|
|
use Drupal\Core\Config\Config;
|
2013-02-27 09:49:26 +00:00
|
|
|
use Drupal\Core\Config\ConfigException;
|
2014-01-09 10:50:21 +00:00
|
|
|
use Drupal\Core\Language\Language;
|
2013-09-13 09:31:12 +00:00
|
|
|
use Drupal\Core\Config\ExtensionInstallStorage;
|
2012-05-16 03:02:24 +00:00
|
|
|
use Drupal\Core\Config\FileStorage;
|
2012-07-03 21:03:18 +00:00
|
|
|
use Drupal\Core\Config\StorageInterface;
|
2014-01-01 10:08:57 +00:00
|
|
|
use Drupal\Core\Entity\EntityTypeInterface;
|
2013-03-10 06:31:56 +00:00
|
|
|
use Symfony\Component\Yaml\Dumper;
|
2014-01-09 10:50:21 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
2012-02-12 16:17:29 +00:00
|
|
|
|
2011-09-05 14:13:26 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* This is the API for configuration storage.
|
|
|
|
*/
|
|
|
|
|
2012-11-04 04:48:01 +00:00
|
|
|
/**
|
|
|
|
* Uninstalls the default configuration of a given extension.
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* The extension type; e.g., 'module' or 'theme'.
|
|
|
|
* @param string $name
|
|
|
|
* The name of the module or theme to install default configuration for.
|
|
|
|
*/
|
|
|
|
function config_uninstall_default_config($type, $name) {
|
2013-12-22 21:03:21 +00:00
|
|
|
$storage = \Drupal::service('config.storage');
|
2012-11-04 04:48:01 +00:00
|
|
|
$config_names = $storage->listAll($name . '.');
|
|
|
|
foreach ($config_names as $config_name) {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::config($config_name)->delete();
|
2012-11-04 04:48:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-12 07:07:10 +00:00
|
|
|
/**
|
2012-09-04 13:51:51 +00:00
|
|
|
* Gets configuration object names starting with a given prefix.
|
|
|
|
*
|
2013-10-03 11:26:25 +00:00
|
|
|
* @see \Drupal\Core\Config\StorageInterface::listAll()
|
2012-01-08 12:26:20 +00:00
|
|
|
*/
|
2012-05-10 14:54:04 +00:00
|
|
|
function config_get_storage_names_with_prefix($prefix = '') {
|
2013-12-22 21:03:21 +00:00
|
|
|
return \Drupal::service('config.storage')->listAll($prefix);
|
2011-09-23 12:23:56 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 00:45:56 +00:00
|
|
|
/**
|
2012-01-08 12:26:20 +00:00
|
|
|
* Retrieves a configuration object.
|
2011-10-17 00:45:56 +00:00
|
|
|
*
|
|
|
|
* This is the main entry point to the configuration API. Calling
|
2013-08-15 04:13:48 +00:00
|
|
|
* @code \Drupal::config('book.admin') @endcode will return a configuration
|
|
|
|
* object in which the book module can store its administrative settings.
|
2011-10-17 00:45:56 +00:00
|
|
|
*
|
2013-08-14 16:54:28 +00:00
|
|
|
* @deprecated as of Drupal 8.0. Use \Drupal::config() instead.
|
2013-06-27 12:10:07 +00:00
|
|
|
*
|
2013-02-27 09:49:26 +00:00
|
|
|
* @param string $name
|
2011-10-17 00:45:56 +00:00
|
|
|
* The name of the configuration object to retrieve. The name corresponds to
|
2013-08-15 04:13:48 +00:00
|
|
|
* a configuration file. For @code \Drupal::config('book.admin') @endcode, the
|
|
|
|
* config object returned will contain the contents of book.admin
|
|
|
|
* configuration file.
|
2012-01-08 01:29:22 +00:00
|
|
|
*
|
2013-10-03 11:26:25 +00:00
|
|
|
* @return \Drupal\Core\Config\Config
|
2012-06-29 17:35:06 +00:00
|
|
|
* A configuration object.
|
2011-10-17 00:45:56 +00:00
|
|
|
*/
|
2012-06-29 17:35:06 +00:00
|
|
|
function config($name) {
|
2013-09-16 03:58:06 +00:00
|
|
|
return \Drupal::config($name);
|
2011-09-23 12:23:56 +00:00
|
|
|
}
|
2012-06-29 17:35:06 +00:00
|
|
|
|
2013-01-03 01:17:20 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity type of a configuration object.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* The configuration object name.
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
* Either the entity type name, or NULL if none match.
|
|
|
|
*/
|
|
|
|
function config_get_entity_type_by_name($name) {
|
2014-01-01 10:08:57 +00:00
|
|
|
$entities = array_filter(\Drupal::entityManager()->getDefinitions(), function (EntityTypeInterface $entity_info) use ($name) {
|
|
|
|
return ($config_prefix = $entity_info->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0;
|
2013-01-03 01:17:20 +00:00
|
|
|
});
|
|
|
|
return key($entities);
|
|
|
|
}
|
Issue #1866610 by Jose Reyero, Gábor Hojtsy, effulgentsia, alexpott, aspilicious, YesCT, fago, sun, dawehner, heyrocker, yched, spearhead93: Introduce Kwalify-inspired schema format for configuration.
2013-01-31 22:09:08 +00:00
|
|
|
|
2013-03-08 17:37:37 +00:00
|
|
|
/**
|
Issue #1866610 by Jose Reyero, Gábor Hojtsy, effulgentsia, alexpott, aspilicious, YesCT, fago, sun, dawehner, heyrocker, yched, spearhead93: Introduce Kwalify-inspired schema format for configuration.
2013-01-31 22:09:08 +00:00
|
|
|
* Returns the typed config manager service.
|
|
|
|
*
|
|
|
|
* Use the typed data manager service for creating typed configuration objects.
|
|
|
|
*
|
2013-10-03 11:26:25 +00:00
|
|
|
* @see \Drupal\Core\TypedData\TypedDataManager::create()
|
Issue #1866610 by Jose Reyero, Gábor Hojtsy, effulgentsia, alexpott, aspilicious, YesCT, fago, sun, dawehner, heyrocker, yched, spearhead93: Introduce Kwalify-inspired schema format for configuration.
2013-01-31 22:09:08 +00:00
|
|
|
*
|
2013-12-20 16:27:41 +00:00
|
|
|
* @return \Drupal\Core\Config\TypedConfigManager
|
Issue #1866610 by Jose Reyero, Gábor Hojtsy, effulgentsia, alexpott, aspilicious, YesCT, fago, sun, dawehner, heyrocker, yched, spearhead93: Introduce Kwalify-inspired schema format for configuration.
2013-01-31 22:09:08 +00:00
|
|
|
*/
|
|
|
|
function config_typed() {
|
2013-12-22 21:03:21 +00:00
|
|
|
return \Drupal::service('config.typed');
|
Issue #1866610 by Jose Reyero, Gábor Hojtsy, effulgentsia, alexpott, aspilicious, YesCT, fago, sun, dawehner, heyrocker, yched, spearhead93: Introduce Kwalify-inspired schema format for configuration.
2013-01-31 22:09:08 +00:00
|
|
|
}
|
2013-03-10 06:31:56 +00:00
|
|
|
|
2013-05-17 14:16:16 +00:00
|
|
|
/**
|
|
|
|
* Creates a configuration snapshot following a successful import.
|
|
|
|
*
|
2013-10-03 11:26:25 +00:00
|
|
|
* @param \Drupal\Core\Config\StorageInterface $source_storage
|
2013-05-17 14:16:16 +00:00
|
|
|
* The storage to synchronize configuration from.
|
2013-10-03 11:26:25 +00:00
|
|
|
* @param \Drupal\Core\Config\StorageInterface $snapshot_storage
|
2013-05-17 14:16:16 +00:00
|
|
|
* The storage to synchronize configuration to.
|
|
|
|
*/
|
|
|
|
function config_import_create_snapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) {
|
|
|
|
$snapshot_storage->deleteAll();
|
|
|
|
foreach ($source_storage->listAll() as $name) {
|
|
|
|
$snapshot_storage->write($name, $source_storage->read($name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-10 06:31:56 +00:00
|
|
|
/**
|
|
|
|
* Return a formatted diff of a named config between two storages.
|
|
|
|
*
|
2013-10-03 11:26:25 +00:00
|
|
|
* @param \Drupal\Core\Config\StorageInterface $source_storage
|
2013-03-10 06:31:56 +00:00
|
|
|
* The storage to diff configuration from.
|
2013-10-03 11:26:25 +00:00
|
|
|
* @param \Drupal\Core\Config\StorageInterface $target_storage
|
2013-03-10 06:31:56 +00:00
|
|
|
* The storage to diff configuration to.
|
|
|
|
* @param string $name
|
|
|
|
* The name of the configuration object to diff.
|
|
|
|
*
|
|
|
|
* @return core/lib/Drupal/Component/Diff
|
|
|
|
* A formatted string showing the difference between the two storages.
|
|
|
|
*
|
|
|
|
* @todo Make renderer injectable
|
|
|
|
*/
|
|
|
|
function config_diff(StorageInterface $source_storage, StorageInterface $target_storage, $name) {
|
|
|
|
require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php';
|
|
|
|
|
|
|
|
// The output should show configuration object differences formatted as YAML.
|
|
|
|
// But the configuration is not necessarily stored in files. Therefore, they
|
|
|
|
// need to be read and parsed, and lastly, dumped into YAML strings.
|
|
|
|
$dumper = new Dumper();
|
|
|
|
$dumper->setIndentation(2);
|
|
|
|
|
|
|
|
$source_data = explode("\n", $dumper->dump($source_storage->read($name), PHP_INT_MAX));
|
|
|
|
$target_data = explode("\n", $dumper->dump($target_storage->read($name), PHP_INT_MAX));
|
|
|
|
|
|
|
|
// Check for new or removed files.
|
|
|
|
if ($source_data === array('false')) {
|
|
|
|
// Added file.
|
|
|
|
$source_data = array(t('File added'));
|
|
|
|
}
|
|
|
|
if ($target_data === array('false')) {
|
|
|
|
// Deleted file.
|
|
|
|
$target_data = array(t('File removed'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Diff($source_data, $target_data);
|
|
|
|
}
|