diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 22 | ||||
-rw-r--r-- | includes/menu.inc | 13 | ||||
-rw-r--r-- | includes/path.inc | 62 | ||||
-rw-r--r-- | includes/theme.inc | 3 |
4 files changed, 99 insertions, 1 deletions
diff --git a/includes/common.inc b/includes/common.inc index e22ce998a..9f8b6a66b 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3591,6 +3591,28 @@ function drupal_html_id($id) { } /** + * Provides a standard HTML class name that identifies a page region. + * + * It is recommended that template preprocess functions apply this class to any + * page region that is output by the theme (Drupal core already handles this in + * the standard template preprocess implementation). Standardizing the class + * names in this way allows modules to implement certain features, such as + * drag-and-drop or dynamic AJAX loading, in a theme-independent way. + * + * @param $region + * The name of the page region (for example, 'page_top' or 'content'). + * + * @return + * An HTML class that identifies the region (for example, 'region-page-top' + * or 'region-content'). + * + * @see template_preprocess_region() + */ +function drupal_region_class($region) { + return drupal_html_class("region-$region"); +} + +/** * Add a JavaScript file, setting or inline code to the page. * * The behavior of this function depends on the parameters it is called with. diff --git a/includes/menu.inc b/includes/menu.inc index ecdd15075..934160684 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -2185,6 +2185,9 @@ function menu_cache_clear($menu_name = 'navigation') { register_shutdown_function('cache_clear_all', 'links:' . $menu_name . ':', 'cache_menu', TRUE); $cache_cleared[$menu_name] = 2; } + + // Also clear the menu system static caches. + menu_reset_static_cache(); } /** @@ -2193,6 +2196,16 @@ function menu_cache_clear($menu_name = 'navigation') { */ function menu_cache_clear_all() { cache_clear_all('*', 'cache_menu', TRUE); + menu_reset_static_cache(); +} + +/** + * Resets the menu system static cache. + */ +function menu_reset_static_cache() { + drupal_static_reset('menu_tree'); + drupal_static_reset('menu_tree_all_data'); + drupal_static_reset('menu_tree_page_data'); } /** diff --git a/includes/path.inc b/includes/path.inc index 3ce40a818..12214daad 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -482,3 +482,65 @@ function path_delete($criteria) { drupal_clear_path_cache(); } +/** + * Determine whether a path is in the administrative section of the site. + * + * By default, paths are considered to be non-administrative. If a path does not + * match any of the patterns in path_get_admin_paths(), or if it matches both + * administrative and non-administrative patterns, it is considered + * non-administrative. + * + * @param $path + * A Drupal path. + * @return + * TRUE if the path is administrative, FALSE otherwise. + * + * @see path_get_admin_paths() + * @see hook_admin_paths() + * @see hook_admin_paths_alter() + */ +function path_is_admin($path) { + $path_map = &drupal_static(__FUNCTION__); + if (!isset($path_map['admin'][$path])) { + $patterns = path_get_admin_paths(); + $path_map['admin'][$path] = drupal_match_path($path, $patterns['admin']); + $path_map['non_admin'][$path] = drupal_match_path($path, $patterns['non_admin']); + } + return $path_map['admin'][$path] && !$path_map['non_admin'][$path]; +} + +/** + * Get a list of administrative and non-administrative paths. + * + * @return array + * An associative array containing the following keys: + * 'admin': An array of administrative paths and regular expressions + * in a format suitable for drupal_match_path(). + * 'non_admin': An array of non-administrative paths and regular expressions. + * + * @see hook_admin_paths() + * @see hook_admin_paths_alter() + */ +function path_get_admin_paths() { + $patterns = &drupal_static(__FUNCTION__); + if (!isset($patterns)) { + $paths = module_invoke_all('admin_paths'); + drupal_alter('admin_paths', $paths); + // Combine all admin paths into one array, and likewise for non-admin paths, + // for easier handling. + $patterns = array(); + $patterns['admin'] = array(); + $patterns['non_admin'] = array(); + foreach ($paths as $path => $enabled) { + if ($enabled) { + $patterns['admin'][] = $path; + } + else { + $patterns['non_admin'][] = $path; + } + } + $patterns['admin'] = implode("\n", $patterns['admin']); + $patterns['non_admin'] = implode("\n", $patterns['non_admin']); + } + return $patterns; +} diff --git a/includes/theme.inc b/includes/theme.inc index 8fb6a5acb..63af79711 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -2580,6 +2580,7 @@ function template_preprocess_maintenance_page(&$variables) { * pluggable template engine. Uses the region name to generate a template file * suggestions. If none are found, the default region.tpl.php is used. * + * @see drupal_region_class() * @see region.tpl.php */ function template_preprocess_region(&$variables) { @@ -2587,7 +2588,7 @@ function template_preprocess_region(&$variables) { $variables['content'] = $variables['elements']['#children']; $variables['region'] = $variables['elements']['#region']; - $region = 'region-' . str_replace('_', '-', $variables['region']); + $region = drupal_region_class($variables['region']); $variables['classes_array'][] = $region; $variables['template_files'][] = $region; } |