diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index 5a7044b..3ce03b8 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -15,6 +15,13 @@ class InstallStorage extends FileStorage { /** + * Folder map indexed by configuration name. + * + * @var array + */ + protected $folders; + + /** * Overrides Drupal\Core\Config\FileStorage::__construct(). */ public function __construct() { @@ -38,17 +45,9 @@ public function __construct() { * afterwards check for a corresponding module or theme. */ public function getFilePath($name) { - // Extract the owner. - $owner = strtok($name, '.'); - // Determine the path to the owner. - $path = FALSE; - foreach (array('profile', 'module', 'theme') as $type) { - if ($path = drupal_get_path($type, $owner)) { - $file = $path . '/config/' . $name . '.' . static::getFileExtension(); - if (file_exists($file)) { - return $file; - } - } + $folders = $this->getAllFolders(); + if (isset($folders[$name])) { + return $folders[$name] . '/' . $name . '.' . $this->getFileExtension(); } // If any code in the early installer requests a configuration object that // does not exist anywhere as default config, then that must be mistake. @@ -86,11 +85,78 @@ public function rename($name, $new_name) { /** * Implements Drupal\Core\Config\StorageInterface::listAll(). - * - * @throws Drupal\Core\Config\StorageException */ public function listAll($prefix = '') { - throw new StorageException('List operation is not allowed during install.'); + $names = array_keys($this->getAllFolders()); + if (!$prefix) { + return $names; + } + else { + $return = array(); + foreach ($names as $index => $name) { + if (strpos($name, $prefix) === 0 ) { + $return[$index] = $names[$index]; + } + } + return $return; + } + } + + /** + * Returns a map of all metadata names and the module they belong to. + * + * @return array + * An array mapping metadata names with directories. + */ + protected function getAllFolders() { + if (!isset($this->folders)) { + $this->folders = $this->getComponentNames('profile', array(drupal_get_profile())); + $this->folders += $this->getComponentNames('module', array_keys(drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0))); + $this->folders += $this->getComponentNames('theme', array_keys(drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'themes'))); + } + return $this->folders; + } + + /** + * Get all configuration names and folders for a list of modules or themes. + * + * @param string $type + * Type of components: 'module' or 'theme' or 'profile'. + * @param array $list + * Array of theme or module names. + * + * @return array + * Folders indexed by configuration name. + */ + public function getComponentNames($type, $list) { + $extension = '.' . $this->getFileExtension(); + $folders = array(); + foreach ($list as $name) { + $directory = $this->getComponentFolder($type, $name); + if (file_exists($directory)) { + $files = glob($directory . '/*' . $extension); + foreach ($files as $filename) { + $name = basename($filename, $extension); + $folders[$name] = $directory; + } + } + } + return $folders; + } + + /** + * Get folder inside each component that contains the files. + * + * @param string $type + * Component type: 'module' or 'theme' or 'profile'. + * @param string $name + * Component name. + * + * @return string + * The configuration folder name for this component. + */ + protected function getComponentFolder($type, $name) { + return drupal_get_path($type, $name) . '/config'; } /** diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php index 1e72c64..14dff64 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\locale\LocaleTypedConfig. + * Contains Drupal\locale\LocaleTypedConfig. */ namespace Drupal\locale; diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php index 31a58ba..7e2d12c 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\locale\Tests\LocaleConfigTranslationTest. + * Contains Drupal\locale\Tests\LocaleConfigTranslationTest. */ namespace Drupal\locale\Tests; diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 3a027e7..d608c7c 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -6,9 +6,12 @@ */ use Drupal\Component\Gettext\PoStreamWriter; +use Drupal\locale\LocaleTypedConfig; use Drupal\locale\Gettext; use Drupal\locale\PoDatabaseReader; use Drupal\Core\Language\Language; +use Drupal\Core\Config\InstallStorage; +use Drupal\Core\Config\StorageException; /** @@ -576,7 +579,7 @@ function locale_translate_batch_refresh($options, &$context) { $context['sandbox']['refresh']['names'] = $names; $context['sandbox']['refresh']['languages'] = $langcodes; $context['sandbox']['refresh']['count'] = count($names); - $context['results']['stats']['configuration'] = 0; + $context['results']['stats']['config'] = 0; } } if (isset($context['sandbox']['refresh'])) { @@ -590,7 +593,7 @@ function locale_translate_batch_refresh($options, &$context) { elseif ($name = array_shift($context['sandbox']['refresh']['names'])) { // Refresh all languages for one object at a time. $count = locale_config_update_multiple(array($name), $context['sandbox']['refresh']['languages']); - $context['results']['stats']['configuration'] += $count; + $context['results']['stats']['config'] += $count; // Not perfect but will give some idea of progress. $context['finished'] = 1 - count($context['sandbox']['refresh']['names']) / $context['sandbox']['refresh']['count']; } @@ -821,10 +824,10 @@ function locale_config_batch_build($names, $langcodes, $options = array()) { * Contains a list of files imported. */ function locale_config_batch_refresh_name($name, $langcodes, &$context) { - if (!isset($context['result']['stats']['configuration'])) { - $context['result']['stats']['configuration'] = 0; + if (!isset($context['result']['stats']['config'])) { + $context['result']['stats']['config'] = 0; } - $context['result']['stats']['configuration'] += locale_config_update_multiple(array($name), $langcodes); + $context['result']['stats']['config'] += locale_config_update_multiple(array($name), $langcodes); $context['result']['names'][] = $name; $context['result']['langcodes'] = $langcodes; $context['finished'] = 1; @@ -840,7 +843,7 @@ function locale_config_batch_refresh_name($name, $langcodes, &$context) { */ function locale_config_batch_finished($success, $results) { if ($success) { - $configuration = isset($results['stats']['configuration']) ? $results['stats']['configuration'] : 0; + $configuration = isset($results['stats']['config']) ? $results['stats']['config'] : 0; if ($configuration) { drupal_set_message(t('The configuration was successfully updated. There are %number configuration objects updated.', array('%number' => $configuration))); watchdog('locale', 'The configuration was successfully updated. %number configuration objects updated.', array('%number' => $configuration));