Skip to content
Snippets Groups Projects
Commit 7becd8a4 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #839556 by dalin, jrchamp, effulgentsia, dmitrig01, David_Rothstein:...

- Patch #839556 by dalin, jrchamp, effulgentsia, dmitrig01, David_Rothstein: fix isset regression in tablesort, add tests, and cleanup theme_process_registry().
parent fc5f56e9
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -73,18 +73,7 @@ protected function init() { ...@@ -73,18 +73,7 @@ protected function init() {
* The current sort direction ("asc" or "desc"). * The current sort direction ("asc" or "desc").
*/ */
protected function getSort() { protected function getSort() {
if (isset($_GET['sort'])) { return tablesort_get_sort($this->header);
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';
} }
/** /**
...@@ -111,32 +100,7 @@ protected function getQueryParameters() { ...@@ -111,32 +100,7 @@ protected function getQueryParameters() {
* - "sql": The name of the database field to sort on. * - "sql": The name of the database field to sort on.
*/ */
protected function order() { protected function order() {
$order = isset($_GET['order']) ? $_GET['order'] : ''; return tablesort_get_order($this->header);
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);
}
}
} }
} }
...@@ -238,29 +202,27 @@ function tablesort_get_query_parameters() { ...@@ -238,29 +202,27 @@ function tablesort_get_query_parameters() {
function tablesort_get_order($headers) { function tablesort_get_order($headers) {
$order = isset($_GET['order']) ? $_GET['order'] : ''; $order = isset($_GET['order']) ? $_GET['order'] : '';
foreach ($headers as $header) { foreach ($headers as $header) {
if (isset($header['data']) && $order == $header['data']) { if (is_array($header)) {
return array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); if (isset($header['data']) && $order == $header['data']) {
} $default = $header;
break;
}
if (isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) { if (empty($default) && isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) {
$default = array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : ''); $default = $header;
}
} }
} }
if (isset($default)) { if (!isset($default)) {
return $default; $default = reset($headers);
} if (!is_array($default)) {
else { $default = array('data' => $default);
// 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' => '');
} }
} }
$default += array('data' => NULL, 'field' => NULL);
return array('name' => $default['data'], 'sql' => $default['field']);
} }
/** /**
...@@ -273,12 +235,15 @@ function tablesort_get_order($headers) { ...@@ -273,12 +235,15 @@ function tablesort_get_order($headers) {
*/ */
function tablesort_get_sort($headers) { function tablesort_get_sort($headers) {
if (isset($_GET['sort'])) { 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 { else {
// Find out which header is currently being sorted.
$ts = tablesort_get_order($headers);
foreach ($headers as $header) { 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']; return $header['sort'];
} }
} }
......
...@@ -362,7 +362,6 @@ function drupal_theme_rebuild() { ...@@ -362,7 +362,6 @@ function drupal_theme_rebuild() {
*/ */
function _theme_process_registry(&$cache, $name, $type, $theme, $path) { function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result = array(); $result = array();
$function = $name . '_theme';
// Processor functions work in two distinct phases with the process // Processor functions work in two distinct phases with the process
// functions always being executed after the preprocess functions. // functions always being executed after the preprocess functions.
...@@ -371,24 +370,43 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { ...@@ -371,24 +370,43 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
'process functions' => 'process', '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)) { if (function_exists($function)) {
$result = $function($cache, $type, $theme, $path); $result = $function($cache, $type, $theme, $path);
foreach ($result as $hook => $info) { 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]['type'] = $type;
$result[$hook]['theme path'] = $path; $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. // conventions.
if (!isset($info['template']) && !isset($info['function'])) { if (!isset($info['template']) && !isset($info['function'])) {
$result[$hook]['function'] = ($type == 'module' ? 'theme_' : $name . '_') . $hook; $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'])) { if (isset($cache[$hook]['includes'])) {
$result[$hook]['includes'] = $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'])) { if (isset($info['file'])) {
$include_file = isset($info['path']) ? $info['path'] : $path; $include_file = isset($info['path']) ? $info['path'] : $path;
$include_file .= '/' . $info['file']; $include_file .= '/' . $info['file'];
...@@ -396,14 +414,10 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { ...@@ -396,14 +414,10 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
$result[$hook]['includes'][] = $include_file; $result[$hook]['includes'][] = $include_file;
} }
// If these keys are left unspecified within overridden entries returned // If the default keys are not set, use the default values registered
// by hook_theme(), carry them forward from the prior entry. This is so // by the module.
// that themes don't need to specify this information, since the module if (isset($cache[$hook])) {
// that registered the theme hook already has. $result[$hook] += array_intersect_key($cache[$hook], $hook_defaults);
foreach (array('variables', 'render element', 'pattern', 'base hook') as $key) {
if (!isset($info[$key]) && isset($cache[$hook][$key])) {
$result[$hook][$key] = $cache[$hook][$key];
}
} }
// The following apply only to theming hooks implemented as templates. // The following apply only to theming hooks implemented as templates.
...@@ -468,7 +482,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { ...@@ -468,7 +482,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) {
} }
// Merge the newly created theme hooks into the existing cache. // 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. // Let themes have variable processors even if they didn't register a template.
......
...@@ -32,6 +32,7 @@ files[] = tests/path.test ...@@ -32,6 +32,7 @@ files[] = tests/path.test
files[] = tests/registry.test files[] = tests/registry.test
files[] = tests/schema.test files[] = tests/schema.test
files[] = tests/session.test files[] = tests/session.test
files[] = tests/tablesort.test
files[] = tests/theme.test files[] = tests/theme.test
files[] = tests/unicode.test files[] = tests/unicode.test
files[] = tests/update.test files[] = tests/update.test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment