Commit 92760988 authored by Dries's avatar Dries

- Patch #648410 by Dave Reid: standardize add 'empty' row functionality to all tables.

parent e7dedc43
......@@ -5427,7 +5427,7 @@ function drupal_common_theme() {
'variables' => array('links' => NULL),
),
'table' => array(
'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE),
'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''),
),
'table_select_header_cell' => array(
'variables' => array(),
......
......@@ -2338,6 +2338,7 @@ function theme_container($variables) {
function theme_tableselect($variables) {
$element = $variables['element'];
$rows = array();
$header = $element['#header'];
if (!empty($element['#options'])) {
// Generate a table row for each selectable item in #options.
foreach ($element['#options'] as $key => $value) {
......@@ -2360,15 +2361,9 @@ function theme_tableselect($variables) {
// Add an empty header or a "Select all" checkbox to provide room for the
// checkboxes/radios in the first table column.
$first_col = $element['#js_select'] ? array(theme('table_select_header_cell')) : array('');
$header = array_merge($first_col, $element['#header']);
$header = array_merge($first_col, $header);
}
else {
// If there are no selectable options, display the empty text over the
// entire width of the table.
$header = $element['#header'];
$rows[] = array(array('data' => $element['#empty'], 'colspan' => count($header)));
}
return theme('table', array('header' => $header, 'rows' => $rows));
return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => $element['#empty']));
}
/**
......
......@@ -2801,15 +2801,8 @@ function _locale_translate_seek() {
);
}
if (count($rows)) {
$output .= theme('table', array('header' => $header, 'rows' => $rows));
if ($pager = theme('pager', array('tags' => NULL))) {
$output .= $pager;
}
}
else {
$output .= t('No strings found for your search.');
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No strings available.')));
$output .= theme('pager', array('tags' => NULL));
return $output;
}
......
......@@ -1706,6 +1706,8 @@ function theme_submenu($variables) {
* within a table. For example, one may easily group three columns and
* apply same background style to all.
* - sticky: Use a "sticky" table header.
* - empty: The message to display in an extra row if table does not have any
* rows.
*
* @return
* An HTML string representing the table.
......@@ -1717,6 +1719,7 @@ function theme_table($variables) {
$caption = $variables['caption'];
$colgroups = $variables['colgroups'];
$sticky = $variables['sticky'];
$empty = $variables['empty'];
// Add sticky headers, if applicable.
if (count($header) && $sticky) {
......@@ -1784,6 +1787,11 @@ function theme_table($variables) {
$ts = array();
}
// Add the 'empty' row message if available.
if (!count($rows) && $empty) {
$rows[] = array(array('data' => $empty, 'colspan' => count($header), 'class' => array('empty', 'message')));
}
// Format the table rows:
if (count($rows)) {
$output .= "<tbody>\n";
......
......@@ -29,10 +29,7 @@ function aggregator_view() {
foreach ($result as $feed) {
$rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '@count items'), ($feed->checked ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->checked))) : t('never')), ($feed->checked && $feed->refresh ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - REQUEST_TIME))) : t('never')), l(t('edit'), "admin/config/services/aggregator/edit/feed/$feed->fid"), l(t('remove items'), "admin/config/services/aggregator/remove/$feed->fid"), l(t('update items'), "admin/config/services/aggregator/update/$feed->fid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => url('admin/config/services/aggregator/add/feed'))), 'colspan' => '5', 'class' => array('message')));
}
$output .= theme('table', array('header' => $header, 'rows' => $rows));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No feeds available.')));
$result = db_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
......@@ -43,10 +40,7 @@ function aggregator_view() {
foreach ($result as $category) {
$rows[] = array(l($category->title, "aggregator/categories/$category->cid"), format_plural($category->items, '1 item', '@count items'), l(t('edit'), "admin/config/services/aggregator/edit/category/$category->cid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No categories available. <a href="@link">Add category</a>.', array('@link' => url('admin/config/services/aggregator/add/category'))), 'colspan' => '5', 'class' => array('message')));
}
$output .= theme('table', array('header' => $header, 'rows' => $rows));
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No categories available.')));
return $output;
}
......
......@@ -19,12 +19,7 @@ function book_admin_overview() {
$rows[] = array(l($book['title'], $book['href'], $book['options']), l(t('edit order and titles'), 'admin/content/book/' . $book['nid']));
}
// If no books were found, let the user know.
if (empty($rows)) {
$rows[] = array(array('data' => t('No books available.'), 'colspan' => 2));
}
return theme('table', array('header' => $headers, 'rows' => $rows));
return theme('table', array('header' => $headers, 'rows' => $rows, 'empty' => t('No books available.')));
}
/**
......@@ -260,4 +255,3 @@ function theme_book_admin_table($variables) {
return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'book-outline')));
}
......@@ -74,15 +74,12 @@ function dblog_overview() {
);
}
if (!$rows) {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 6));
}
$build['dblog_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'admin-dblog'),
'#empty' => t('No log messages available.'),
);
$build['dblog_pager'] = array('#theme' => 'pager');
......@@ -120,14 +117,11 @@ function dblog_top($type) {
$rows[] = array($dblog->count, truncate_utf8(_dblog_format_message($dblog), 56, TRUE, TRUE));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 2));
}
$build['dblog_top_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No log messages available.'),
);
$build['dblog_top_pager'] = array('#theme' => 'pager');
......
......@@ -429,7 +429,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t("Search didn't find the string."));
$this->assertText(t('No strings available.'), t("Search didn't find the string."));
// Ensure untranslated string appears if searching on 'only untranslated
// strings'.
......@@ -440,7 +440,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings found for your search.'), t('Search found the string.'));
$this->assertNoText(t('No strings available.'), t('Search found the string.'));
// Add translation.
// Assume this is the only result, given the random name.
......@@ -463,7 +463,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings found for your search.'), t('Search found the translation.'));
$this->assertNoText(t('No strings available.'), t('Search found the translation.'));
// Ensure translated source string doesn't appear if searching on 'only
// untranslated strings'.
......@@ -474,7 +474,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t("Search didn't find the source string."));
$this->assertText(t('No strings available.'), t("Search didn't find the source string."));
// Ensure translated string doesn't appear if searching on 'only
// untranslated strings'.
......@@ -485,7 +485,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t("Search didn't find the translation."));
$this->assertText(t('No strings available.'), t("Search didn't find the translation."));
// Ensure translated string does appear if searching on the custom language.
$search = array(
......@@ -495,7 +495,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings found for your search.'), t('Search found the translation.'));
$this->assertNoText(t('No strings available.'), t('Search found the translation.'));
// Ensure translated string doesn't appear if searching on English.
$search = array(
......@@ -505,7 +505,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t("Search didn't find the translation."));
$this->assertText(t('No strings available.'), t("Search didn't find the translation."));
// Search for a string that isn't in the system.
$unavailable_string = $this->randomName(16);
......@@ -516,7 +516,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t("Search didn't find the invalid string."));
$this->assertText(t('No strings available.'), t("Search didn't find the invalid string."));
}
}
......@@ -612,7 +612,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t('String not overwritten by imported string.'));
$this->assertText(t('No strings available.'), t('String not overwritten by imported string.'));
// Try importing a .po file with overriding strings, and ensure existing
......@@ -632,7 +632,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings found for your search.'), t('String overwritten by imported string.'));
$this->assertNoText(t('No strings available.'), t('String overwritten by imported string.'));
}
/**
......@@ -671,7 +671,7 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
'group' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings found for your search.'), t('String successfully imported.'));
$this->assertNoText(t('No strings available.'), t('String successfully imported.'));
}
/**
......@@ -1797,5 +1797,3 @@ class LocalizeDateFormatsFunctionalTest extends DrupalWebTestCase {
$this->assertText($french_date, t('French date format appears'));
}
}
......@@ -44,14 +44,11 @@ function node_overview_types() {
}
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No content types available. <a href="@link">Add content type</a>.', array('@link' => url('admin/structure/types/add'))), 'colspan' => '5', 'class' => array('message')));
}
$build['node_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows
'#rows' => $rows,
'#empty' => t('No content types available.'),
);
return $build;
......@@ -130,7 +127,7 @@ function node_type_form($form, &$form_state, $type = NULL) {
'#title' => t('Description'),
'#type' => 'textarea',
'#default_value' => $type->description,
'#description' => t('Describe this content type. It will be displayed on the <em>Add new content</em> page.'),
'#description' => t('Describe this content type. It will be displayed on the <em>Add new content</em> page.'),
);
$form['additional_settings'] = array(
......
......@@ -554,18 +554,11 @@ function node_admin_nodes() {
}
// Otherwise, use a simple table.
else {
// Display an empty message like in the tableselect.
if (empty($options)) {
$row = array(
'data' => t('No content available.'),
'colspan' => count($header),
);
$options = array($row);
}
$form['nodes'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $options,
'#empty' => t('No content available.'),
);
}
......
......@@ -61,15 +61,11 @@ function path_admin_overview($keys = NULL) {
$rows[] = $row;
}
if (empty($rows)) {
$empty_message = $keys ? t('No URL aliases found.') : t('No URL aliases available. <a href="@link">Add alias</a>.', array('@link' => url('admin/config/search/path/add'))) ;
$rows[] = array(array('data' => $empty_message, 'colspan' => ($multilanguage ? 5 : 4)));
}
$build['path_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows
'#rows' => $rows,
'#empty' => t('No URL aliases available.'),
);
$build['path_pager'] = array('#theme' => 'pager');
......
......@@ -148,9 +148,6 @@ function theme_profile_admin_overview($variables) {
$rows[] = array('data' => $row, 'class' => array('draggable'));
}
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No fields available.'), 'colspan' => 7));
}
$header = array(t('Title'), t('Name'), t('Type'));
if (isset($form['submit'])) {
......@@ -159,7 +156,7 @@ function theme_profile_admin_overview($variables) {
}
$header[] = array('data' => t('Operations'), 'colspan' => 2);
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'profile-fields')));
$output = theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No fields available.'), 'attributes' => array('id' => 'profile-fields')));
$output .= drupal_render_children($form);
return $output;
......
......@@ -35,14 +35,11 @@ function statistics_recent_hits() {
l(t('details'), "admin/reports/access/$log->aid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
$build['statistics_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_pager'] = array('#theme' => 'pager');
return $build;
......@@ -82,15 +79,12 @@ function statistics_top_pages() {
$rows[] = array($page->hits, _statistics_format_item($page->title, $page->path), t('%time ms', array('%time' => round($page->average_time))), format_interval(round($page->total_time / 1000)));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH);
$build['statistics_top_pages_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_top_pages_pager'] = array('#theme' => 'pager');
return $build;
......@@ -136,15 +130,12 @@ function statistics_top_visitors() {
$rows[] = array($account->hits, ($account->uid ? theme('username', array('account' => $account)) : $account->hostname), format_interval(round($account->total / 1000)), (user_access('block IP addresses') && !$account->uid) ? $ban_link : '');
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH);
$build['statistics_top_visitors_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_top_visitors_pager'] = array('#theme' => 'pager');
return $build;
......@@ -186,14 +177,11 @@ function statistics_top_referrers() {
$rows[] = array($referrer->hits, _statistics_link($referrer->url), t('@time ago', array('@time' => format_interval(REQUEST_TIME - $referrer->last))));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
}
$build['statistics_top_referrers_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_top_referrers_pager'] = array('#theme' => 'pager');
return $build;
......
......@@ -38,15 +38,12 @@ function statistics_node_tracker() {
);
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title($node->title[FIELD_LANGUAGE_NONE][0]['value']);
$build['statistics_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_pager'] = array('#theme' => 'pager');
return $build;
......@@ -79,15 +76,12 @@ function statistics_user_tracker() {
l(t('details'), "admin/reports/access/$log->aid"));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 3));
}
drupal_set_title(format_username($account));
$build['statistics_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows
'#rows' => $rows,
'#empty' => t('No statistics available.'),
);
$build['statistics_pager'] = array('#theme' => 'pager');
return $build;
......
......@@ -2493,12 +2493,7 @@ function theme_system_modules_uninstall($variables) {
);
}
// Only display table if there are modules that can be uninstalled.
if (empty($rows)) {
$rows[] = array(array('data' => t('No modules are available to uninstall.'), 'colspan' => '3', 'align' => 'center', 'class' => array('message')));
}
$output = theme('table', array('header' => $header, 'rows' => $rows));
$output = theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No modules are available to uninstall.')));
$output .= drupal_render_children($form);
return $output;
......@@ -2648,14 +2643,11 @@ function system_date_time_formats() {
}
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No custom date formats available. <a href="@link">Add date format</a>.', array('@link' => url('admin/config/regional/date-time/formats/add'))), 'colspan' => '5', 'class' => array('message')));
}
$build['date_formats_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => ('No custom date formats available.'),
);
return $build;
......@@ -3012,4 +3004,3 @@ function system_actions_remove_orphans() {
actions_synchronize(TRUE);
drupal_goto('admin/config/system/actions/manage');
}
......@@ -79,17 +79,13 @@ function theme_taxonomy_overview_vocabularies($variables) {
}
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No vocabularies available. <a href="@link">Add vocabulary</a>.', array('@link' => url('admin/structure/taxonomy/add'))), 'colspan' => '5'));
}
$header = array(t('Vocabulary name'));
if (isset($form['submit'])) {
$header[] = t('Weight');
drupal_add_tabledrag('taxonomy', 'order', 'sibling', 'vocabulary-weight');
}
$header[] = array('data' => t('Operations'), 'colspan' => '3');
return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'taxonomy'))) . drupal_render_children($form);
return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No vocabularies available.'),'attributes' => array('id' => 'taxonomy'))) . drupal_render_children($form);
}
/**
......@@ -704,7 +700,7 @@ function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary =
'#default_value' => $parent,
'#multiple' => TRUE,
);
}
$form['advanced']['weight'] = array(
'#type' => 'textfield',
......
......@@ -37,6 +37,7 @@ function tracker_page($account = NULL, $set_title = FALSE) {
->execute()
->fetchAllAssoc('nid');
$rows = array();
if (!empty($nodes)) {
// Now, get the data and put into the placeholder array
$result = db_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));
......@@ -46,7 +47,6 @@ function tracker_page($account = NULL, $set_title = FALSE) {
}
// Finally display the data
$rows = array();
foreach ($nodes as $node) {
// Determine the number of comments:
$comments = 0;
......@@ -68,14 +68,12 @@ function tracker_page($account = NULL, $set_title = FALSE) {
);
}
}
else {
$rows[] = array(array('data' => t('No content available.'), 'colspan' => '5'));
}
$page['tracker'] = array(
'#rows' => $rows,
'#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')),
'#theme' => 'table',
'#empty' => t('No content available.'),
'#attached' => array(
'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array('preprocess' => FALSE)),
),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment