diff --git a/core/includes/module.inc b/core/includes/module.inc index ab45576..a2470b9 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -253,6 +253,7 @@ function _module_build_dependencies($files) { $files[$module]->requires = isset($data['paths']) ? $data['paths'] : array(); $files[$module]->sort = $data['weight']; } + dsm($files); return $files; } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 504030e..eab5ba6 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -10,6 +10,15 @@ use Drupal\Core\Utility\ThemeRegistry; + +/** + * @file + * API for loading and interacting with Drupal modules. + */ + +use Drupal\Component\Graph\Graph; +use Drupal\Core\Config\DatabaseStorage; + /** * @defgroup content_flags Content markers * @{ @@ -2819,3 +2828,65 @@ function template_preprocess_region(&$variables) { $variables['attributes']['class'][] = drupal_region_class($variables['region']); $variables['theme_hook_suggestions'][] = 'region__' . $variables['region']; } + +/** + * Find dependencies any level deep and fill in required by information too. + * + * @param $files + * The array of filesystem objects used to rebuild the cache. + * + * @return + * The same array with the new keys for each module: + * - requires: An array with the keys being the modules that this module + * requires. + * - required_by: An array with the keys being the modules that will not work + * without this module. + */ +function _theme_build_dependencies($files) { + $return = array(); + + foreach ($files as $file) { + $graph[$file->name]['edges'] = array(); + if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) { + foreach ($file->info['dependencies'] as $dependency) { + $dependency_data = drupal_parse_dependency($dependency); + $graph[$file->name]['edges'][$dependency_data['name']] = $dependency_data; + } + } + if (isset($file->base_themes) && is_array($file->base_themes)) { + foreach ($file->base_themes as $base_key => $base_theme) { + $base_theme = drupal_parse_info_file(drupal_get_path('theme', $base_key) . '/' . $base_key . '.info'); + + if (count($base_theme) > 0) { + foreach ($base_theme['dependencies'] as $dependency) { + $dependency_data = drupal_parse_dependency($dependency); + $graph[$file->name]['edges'][$dependency_data['name']] = $dependency_data; + } + } + } + } + } + $graph_object = new Graph($graph); + $graph = $graph_object->searchAndSort(); + foreach ($graph as $theme => $data) { + $files = array(); + foreach ($data['paths'] as $module) { + $files[$module['name']] = new stdClass(); + $files[$module['name']]->name = $module['name']; + + $status = db_select('system', 's') + ->fields('s', array('status')) + ->condition('name', $module['name'], '=') + ->execute() + ->fetchAssoc(); + + $files[$module['name']]->status = isset($status) ? $status['status'] : false; + } + + $return[$theme] = new stdClass(); +// $return[$theme]->required_by = isset($data['reverse_paths']) ? $data['reverse_paths'] : array(); + $return[$theme]->requires = isset($files) ? $files : array(); + $return[$theme]->sort = $data['weight']; + } + return $return; +} diff --git a/core/modules/system/system.admin.css b/core/modules/system/system.admin.css index 957d3e0..985f0fa 100644 --- a/core/modules/system/system.admin.css +++ b/core/modules/system/system.admin.css @@ -207,6 +207,9 @@ table.screenshot { .system-themes-list-disabled .theme-info { min-height: 170px; } +.theme-selector .theme-requires { + margin-bottom: 10px; +} .theme-selector .incompatible { margin-top: 10px; font-weight: bold; diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 72c50d4..3cb54c1 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -282,16 +282,37 @@ function system_theme_enable() { $theme = $_REQUEST['theme']; // Get current list of themes. $themes = list_themes(); + $theme_deps = _theme_build_dependencies($themes); // Check if the specified theme is one recognized by the system. if (!empty($themes[$theme])) { - theme_enable(array($theme)); - drupal_set_message(t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name']))); + if ($theme_deps[$theme]->requires) { + + $modules = $theme_deps[$theme]->requires; + $required = '