diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1cd178c..b748ee8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -235,9 +235,14 @@ function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) { * The filename of the requested item or NULL if the item is not found. */ function drupal_get_filename($type, $name, $filename = NULL) { + // Return NULL right away if $type or $name is empty. + if (empty($type) || empty($name)) { + return NULL; + } + // The location of files will not change during the request, so do not use // drupal_static(). - static $files = array(); + static $files = array(), $bad = array(); // Type 'core' only exists to simplify application-level logic; it always maps // to the /core directory, whereas $name is ignored. It is only requested via @@ -261,22 +266,38 @@ function drupal_get_filename($type, $name, $filename = NULL) { $files[$type][$name] = $filename; } elseif (!isset($files[$type][$name])) { + if (empty($bad)) { + $cache = NULL; + // In early stages of the bootstrap process the container may not be set + // inside of the Drupal class. + $cache_object = \Drupal::cache('bootstrap'); + if (!empty($cache_object) && is_object($cache_object) && method_exists($cache_object, 'get')) { + $cache = $cache_object->get('drupal_get_filename:bad', TRUE); + } + if ($cache && $cache->data) { + $bad = $cache->data; + } + else { + $bad = array(); + } + } + // If the pathname of the requested extension is not known, try to retrieve // the list of extension pathnames from various providers, checking faster // providers first. // Retrieve the current module list (derived from the service container). - if ($type == 'module' && \Drupal::hasService('module_handler')) { + if (!isset($bad[$type][$name]) && $type == 'module' && \Drupal::hasService('module_handler')) { foreach (\Drupal::moduleHandler()->getModuleList() as $module_name => $module) { $files[$type][$module_name] = $module->getPathname(); } } // If still unknown, retrieve the file list prepared in state by // system_rebuild_module_data() and system_rebuild_theme_data(). - if (!isset($files[$type][$name]) && \Drupal::hasService('state')) { + if (!isset($bad[$type][$name]) && !isset($files[$type][$name]) && \Drupal::hasService('state')) { $files[$type] += \Drupal::state()->get('system.' . $type . '.files', array()); } // If still unknown, perform a filesystem scan. - if (!isset($files[$type][$name])) { + if (!isset($bad[$type][$name]) && !isset($files[$type][$name])) { $listing = new ExtensionDiscovery(DRUPAL_ROOT); // Prevent an infinite recursion by this legacy function. if ($original_type == 'profile') { @@ -291,6 +312,20 @@ function drupal_get_filename($type, $name, $filename = NULL) { if (isset($files[$type][$name])) { return $files[$type][$name]; } + elseif (!isset($bad[$type][$name])) { + // Add the missing file to a temporary cache and throw an alert. + $bad[$type][$name] = TRUE; + // In early stages of the bootstrap process the container may not be set + // inside of the Drupal class. + $cache_object = \Drupal::cache('bootstrap'); + if (!empty($cache_object) && is_object($cache_object) && method_exists($cache_object, 'set')) { + $cache_object->set('drupal_get_filename:bad', $bad, REQUEST_TIME); + } + $logger_object = \Drupal::logger('system'); + if (!empty($logger_object) && is_object($logger_object) && method_exists($logger_object, 'error')) { + $logger_object->error('The following @type is missing from the file system: @name', array('@type' => $type, '@name' => $name)); + } + } } /** diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 141686f..3bbce9f 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -259,7 +259,7 @@ public static function database() { * @ingroup cache */ public static function cache($bin = 'default') { - return static::$container->get('cache.' . $bin); + return static::$container ? static::$container->get('cache.' . $bin) : NULL; } /** @@ -596,7 +596,7 @@ public static function isConfigSyncing() { * The logger for this channel. */ public static function logger($channel) { - return static::$container->get('logger.factory')->get($channel); + return static::$container ? static::$container->get('logger.factory')->get($channel) : NULL; } /** diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php index cb2833e..cbe3ae8 100644 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -99,7 +99,11 @@ protected function getAllFolders() { // 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())); + $profile_folders = array(); + $profile = drupal_get_profile(); + if (!empty($profile)) { + $profile_folders = $this->getComponentNames('profile', array($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);