diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-04-10 16:26:08 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-04-10 16:26:08 -0700 |
commit | 4b3d9a015420499d9079a0a95c5a0dc4968b4a63 (patch) | |
tree | 25058faac6e36dbe6bde0c1fe6fd86b1999defaa /includes | |
parent | ee09da916ca1693c95da9c598756fa1eea8e319d (diff) | |
download | brdo-4b3d9a015420499d9079a0a95c5a0dc4968b4a63.tar.gz brdo-4b3d9a015420499d9079a0a95c5a0dc4968b4a63.tar.bz2 |
Issue #839556 by dalin, jrchamp, effulgentsia, dmitrig01, David_Rothstein: fix isset regression in tablesort, add tests, and cleanup theme_process_registry().
Diffstat (limited to 'includes')
-rw-r--r-- | includes/tablesort.inc | 81 | ||||
-rw-r--r-- | includes/theme.inc | 46 |
2 files changed, 53 insertions, 74 deletions
diff --git a/includes/tablesort.inc b/includes/tablesort.inc index 55a3f4cec..121a1b909 100644 --- a/includes/tablesort.inc +++ b/includes/tablesort.inc @@ -73,18 +73,7 @@ class TableSort extends SelectQueryExtender { * The current sort direction ("asc" or "desc"). */ protected function getSort() { - if (isset($_GET['sort'])) { - return ($_GET['sort'] == 'desc') ? 'desc' : 'asc'; - } - // User has not specified a sort. Use default if specified; otherwise use "asc". - else { - foreach ($this->header as $header) { - if (is_array($header) && isset($header['sort'])) { - return $header['sort']; - } - } - } - return 'asc'; + return tablesort_get_sort($this->header); } /** @@ -111,32 +100,7 @@ class TableSort extends SelectQueryExtender { * - "sql": The name of the database field to sort on. */ protected function order() { - $order = isset($_GET['order']) ? $_GET['order'] : ''; - foreach ($this->header as $header) { - if (isset($header['data']) && $order == $header['data']) { - return array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); - } - - if (isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) { - $default = array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); - } - } - - if (isset($default)) { - return $default; - } - else { - // The first column specified is initial 'order by' field unless otherwise specified - $headers = array_values($this->header); - $header = $headers[0]; - if (is_array($header)) { - $header += array('data' => NULL, 'field' => NULL); - return array('name' => $header['data'], 'sql' => $header['field']); - } - else { - return array('name' => $header); - } - } + return tablesort_get_order($this->header); } } @@ -238,29 +202,27 @@ function tablesort_get_query_parameters() { function tablesort_get_order($headers) { $order = isset($_GET['order']) ? $_GET['order'] : ''; foreach ($headers as $header) { - if (isset($header['data']) && $order == $header['data']) { - return array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); - } + if (is_array($header)) { + if (isset($header['data']) && $order == $header['data']) { + $default = $header; + break; + } - if (isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) { - $default = array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); + if (empty($default) && isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) { + $default = $header; + } } } - if (isset($default)) { - return $default; - } - else { - // The first column specified is the initial 'order by' field unless otherwise specified. - $first = current($headers); - if (is_array($first)) { - $first += array('data' => NULL, 'field' => NULL); - return array('name' => $first['data'], 'sql' => $first['field']); - } - else { - return array('name' => $first, 'sql' => ''); + if (!isset($default)) { + $default = reset($headers); + if (!is_array($default)) { + $default = array('data' => $default); } } + + $default += array('data' => NULL, 'field' => NULL); + return array('name' => $default['data'], 'sql' => $default['field']); } /** @@ -273,12 +235,15 @@ function tablesort_get_order($headers) { */ function tablesort_get_sort($headers) { if (isset($_GET['sort'])) { - return ($_GET['sort'] == 'desc') ? 'desc' : 'asc'; + return (strtolower($_GET['sort']) == 'desc') ? 'desc' : 'asc'; } - // User has not specified a sort. Use default if specified; otherwise use "asc". + // The user has not specified a sort. Use the default for the currently sorted + // header if specified; otherwise use "asc". else { + // Find out which header is currently being sorted. + $ts = tablesort_get_order($headers); foreach ($headers as $header) { - if (isset($header['sort'])) { + if (is_array($header) && isset($header['data']) && $header['data'] == $ts['name'] && isset($header['sort'])) { return $header['sort']; } } diff --git a/includes/theme.inc b/includes/theme.inc index 806e5ee9f..81165b36a 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -362,7 +362,6 @@ function drupal_theme_rebuild() { */ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $result = array(); - $function = $name . '_theme'; // Processor functions work in two distinct phases with the process // functions always being executed after the preprocess functions. @@ -371,24 +370,43 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { 'process functions' => 'process', ); + $hook_defaults = array( + 'variables' => TRUE, + 'render element' => TRUE, + 'pattern' => TRUE, + 'base hook' => TRUE, + ); + + // Invoke the hook_theme() implementation, process what is returned, and + // merge it into $cache. + $function = $name . '_theme'; if (function_exists($function)) { $result = $function($cache, $type, $theme, $path); foreach ($result as $hook => $info) { + // When a theme or engine overrides a module's theme function + // $result[$hook] will only contain key/value pairs for information being + // overridden. Pull the rest of the information from what was defined by + // an earlier hook. + + // Fill in the type and path of the module, theme, or engine that + // implements this theme function. $result[$hook]['type'] = $type; $result[$hook]['theme path'] = $path; - // if function and file are left out, default to standard naming + + // If function and file are omitted, default to standard naming // conventions. if (!isset($info['template']) && !isset($info['function'])) { $result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name . '_') . $hook; } - // If a path is set in the info, use what was set. Otherwise use the - // default path. This is mostly so system.module can declare theme - // functions on behalf of core .include files. - // All files are included to be safe. Conditionally included - // files can prevent them from getting registered. + if (isset($cache[$hook]['includes'])) { $result[$hook]['includes'] = $cache[$hook]['includes']; } + + // If the theme implementation defines a file, then also use the path + // that it defined. Otherwise use the default path. This allows + // system.module to declare theme functions on behalf of core .include + // files. if (isset($info['file'])) { $include_file = isset($info['path']) ? $info['path'] : $path; $include_file .= '/' . $info['file']; @@ -396,14 +414,10 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $result[$hook]['includes'][] = $include_file; } - // If these keys are left unspecified within overridden entries returned - // by hook_theme(), carry them forward from the prior entry. This is so - // that themes don't need to specify this information, since the module - // that registered the theme hook already has. - foreach (array('variables', 'render element', 'pattern', 'base hook') as $key) { - if (!isset($info[$key]) && isset($cache[$hook][$key])) { - $result[$hook][$key] = $cache[$hook][$key]; - } + // If the default keys are not set, use the default values registered + // by the module. + if (isset($cache[$hook])) { + $result[$hook] += array_intersect_key($cache[$hook], $hook_defaults); } // The following apply only to theming hooks implemented as templates. @@ -468,7 +482,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { } // Merge the newly created theme hooks into the existing cache. - $cache = array_merge($cache, $result); + $cache = $result + $cache; } // Let themes have variable processors even if they didn't register a template. |