Revision 27e02aed
Added by Assos Assos over 4 years ago
drupal7/includes/theme.inc | ||
---|---|---|
1911 | 1911 |
/** |
1912 | 1912 |
* Returns HTML for a table. |
1913 | 1913 |
* |
1914 |
* @param $variables |
|
1914 |
* @param array $variables
|
|
1915 | 1915 |
* An associative array containing: |
1916 | 1916 |
* - header: An array containing the table headers. Each element of the array |
1917 | 1917 |
* can be either a localized string or an associative array with the |
... | ... | |
1948 | 1948 |
* ) |
1949 | 1949 |
* ); |
1950 | 1950 |
* @endcode |
1951 |
* - footer: An array of table rows which will be printed within a <tfoot> |
|
1952 |
* tag, in the same format as the rows element (see above). |
|
1953 |
* The structure is the same the one defined for the "rows" key except |
|
1954 |
* that the no_striping boolean has no effect, there is no rows striping |
|
1955 |
* for the table footer. |
|
1951 | 1956 |
* - attributes: An array of HTML attributes to apply to the table tag. |
1952 | 1957 |
* - caption: A localized string to use for the <caption> tag. |
1953 | 1958 |
* - colgroups: An array of column groups. Each element of the array can be |
... | ... | |
1984 | 1989 |
* - sticky: Use a "sticky" table header. |
1985 | 1990 |
* - empty: The message to display in an extra row if table does not have any |
1986 | 1991 |
* rows. |
1992 |
* |
|
1993 |
* @return string |
|
1994 |
* The HTML output. |
|
1987 | 1995 |
*/ |
1988 |
function theme_table($variables) { |
|
1996 |
function theme_table(array $variables) {
|
|
1989 | 1997 |
$header = $variables['header']; |
1990 | 1998 |
$rows = $variables['rows']; |
1991 | 1999 |
$attributes = $variables['attributes']; |
... | ... | |
2049 | 2057 |
if (!empty($header)) { |
2050 | 2058 |
foreach ($header as $header_cell) { |
2051 | 2059 |
if (is_array($header_cell)) { |
2052 |
$header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1; |
|
2060 |
$header_count += isset($header_cell['colspan']) ? |
|
2061 |
$header_cell['colspan'] : 1; |
|
2053 | 2062 |
} |
2054 | 2063 |
else { |
2055 | 2064 |
$header_count++; |
2056 | 2065 |
} |
2057 | 2066 |
} |
2058 | 2067 |
} |
2059 |
$rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message'))); |
|
2068 |
$rows[] = array( |
|
2069 |
array( |
|
2070 |
'data' => $empty, |
|
2071 |
'colspan' => $header_count, |
|
2072 |
'class' => array( |
|
2073 |
'empty', |
|
2074 |
'message' |
|
2075 |
), |
|
2076 |
), |
|
2077 |
); |
|
2060 | 2078 |
} |
2061 | 2079 |
|
2062 |
// Format the table header:
|
|
2080 |
// Format the table header.
|
|
2063 | 2081 |
if (!empty($header)) { |
2064 | 2082 |
$ts = tablesort_init($header); |
2065 | 2083 |
// HTML requires that the thead tag has tr tags in it followed by tbody |
... | ... | |
2069 | 2087 |
$cell = tablesort_header($cell, $header, $ts); |
2070 | 2088 |
$output .= _theme_table_cell($cell, TRUE); |
2071 | 2089 |
} |
2072 |
// Using ternary operator to close the tags based on whether or not there are rows |
|
2090 |
// Using ternary operator to close the tags based on whether |
|
2091 |
// or not there are rows. |
|
2073 | 2092 |
$output .= (!empty($rows) ? " </tr></thead>\n" : "</tr>\n"); |
2074 | 2093 |
} |
2075 | 2094 |
else { |
2076 | 2095 |
$ts = array(); |
2077 | 2096 |
} |
2078 | 2097 |
|
2079 |
// Format the table rows: |
|
2098 |
// Format the table and footer rows. |
|
2099 |
$sections = array(); |
|
2100 |
|
|
2080 | 2101 |
if (!empty($rows)) { |
2081 |
$output .= "<tbody>\n"; |
|
2102 |
$sections['tbody'] = $rows; |
|
2103 |
} |
|
2104 |
|
|
2105 |
if (!empty($variables['footer'])) { |
|
2106 |
$sections['tfoot'] = $variables['footer']; |
|
2107 |
} |
|
2108 |
|
|
2109 |
// tbody and tfoot have the same structure and are built using the same |
|
2110 |
// procedure. |
|
2111 |
foreach ($sections as $tag => $content) { |
|
2112 |
$output .= "<" . $tag . ">\n"; |
|
2082 | 2113 |
$flip = array('even' => 'odd', 'odd' => 'even'); |
2083 | 2114 |
$class = 'even'; |
2084 |
foreach ($rows as $number => $row) { |
|
2085 |
// Check if we're dealing with a simple or complex row |
|
2115 |
$default_no_striping = ($tag === 'tfoot'); |
|
2116 |
|
|
2117 |
foreach ($content as $number => $row) { |
|
2118 |
// Check if we're dealing with a simple or complex row. |
|
2086 | 2119 |
if (isset($row['data'])) { |
2087 | 2120 |
$cells = $row['data']; |
2088 |
$no_striping = isset($row['no_striping']) ? $row['no_striping'] : FALSE; |
|
2121 |
$no_striping = isset($row['no_striping']) ? |
|
2122 |
$row['no_striping'] : $default_no_striping; |
|
2089 | 2123 |
|
2090 | 2124 |
// Set the attributes array and exclude 'data' and 'no_striping'. |
2091 | 2125 |
$attributes = $row; |
... | ... | |
2095 | 2129 |
else { |
2096 | 2130 |
$cells = $row; |
2097 | 2131 |
$attributes = array(); |
2098 |
$no_striping = FALSE;
|
|
2132 |
$no_striping = $default_no_striping;
|
|
2099 | 2133 |
} |
2134 |
|
|
2100 | 2135 |
if (!empty($cells)) { |
2101 |
// Add odd/even class |
|
2136 |
// Add odd/even class.
|
|
2102 | 2137 |
if (!$no_striping) { |
2103 | 2138 |
$class = $flip[$class]; |
2104 | 2139 |
$attributes['class'][] = $class; |
2105 | 2140 |
} |
2106 | 2141 |
|
2107 |
// Build row |
|
2142 |
// Build row.
|
|
2108 | 2143 |
$output .= ' <tr' . drupal_attributes($attributes) . '>'; |
2109 | 2144 |
$i = 0; |
2110 | 2145 |
foreach ($cells as $cell) { |
... | ... | |
2114 | 2149 |
$output .= " </tr>\n"; |
2115 | 2150 |
} |
2116 | 2151 |
} |
2117 |
$output .= "</tbody>\n"; |
|
2152 |
|
|
2153 |
$output .= "</" . $tag . ">\n"; |
|
2118 | 2154 |
} |
2119 | 2155 |
|
2120 | 2156 |
$output .= "</table>\n"; |
2157 |
|
|
2121 | 2158 |
return $output; |
2122 | 2159 |
} |
2123 | 2160 |
|
Also available in: Unified diff
-a