summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-08-15 23:48:45 +0100
committerAlex Pott2014-08-15 23:48:45 +0100
commit28ef6b28c3c125b0498d9cbd0372826c434ede51 (patch)
treec2b29b425832796d015496623470923f759e4cf2
parent17fcc16482bdc6664ef62fff2e24c8c4c86b4229 (diff)
Issue #2152227 by JeroenT, joelpittet, steinmb, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_tableselect() to #theme table__tableselect.
-rw-r--r--core/includes/form.inc49
-rw-r--r--core/includes/theme.inc3
-rw-r--r--core/modules/system/system.module5
3 files changed, 26 insertions, 31 deletions
diff --git a/core/includes/form.inc b/core/includes/form.inc
index fb9add4..0f19ca2 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -1348,18 +1348,19 @@ function form_process_container($element, FormStateInterface $form_state) {
}
/**
- * Returns HTML for a table with radio buttons or checkboxes.
+ * Prepares a 'tableselect' #type element for rendering.
*
- * @param $variables
- * An associative array containing:
- * - element: An associative array containing the properties and children of
- * the tableselect element. Properties used: #header, #options, #empty,
- * and #js_select. The #options property is an array of selection options;
- * each array element of #options is an array of properties. These
- * properties can include #attributes, which is added to the
- * table row's HTML attributes; see theme_table(). An example of per-row
- * options:
- * @code
+ * Adds a column of radio buttons or checkboxes for each row of a table.
+ *
+ * @param array $element
+ * An associative array containing the properties and children of
+ * the tableselect element. Properties used: #header, #options, #empty,
+ * and #js_select. The #options property is an array of selection options;
+ * each array element of #options is an array of properties. These
+ * properties can include #attributes, which is added to the
+ * table row's HTML attributes; see table.html.twig. An example of per-row
+ * options:
+ * @code
* $options = array(
* array(
* 'title' => 'How to Learn Drupal',
@@ -1385,15 +1386,12 @@ function form_process_container($element, FormStateInterface $form_state) {
* '#options' => $options,
* '#empty' => t('No content available.'),
* );
- * @endcode
+ * @endcode
*
- * @ingroup themeable
+ * @return array
+ * The processed element.
*/
-function theme_tableselect($variables) {
- $element = $variables['element'];
- $table = array(
- '#type' => 'table',
- );
+function form_pre_render_tableselect($element) {
$rows = array();
$header = $element['#header'];
if (!empty($element['#options'])) {
@@ -1433,7 +1431,7 @@ function theme_tableselect($variables) {
// checkboxes/radios in the first table column.
if ($element['#js_select']) {
// Add a "Select all" checkbox.
- $table['#attached']['library'][] = 'core/drupal.tableselect';
+ $element['#attached']['library'][] = 'core/drupal.tableselect';
array_unshift($header, array('class' => array('select-all')));
}
else {
@@ -1442,14 +1440,11 @@ function theme_tableselect($variables) {
array_unshift($header, '');
}
}
- $table += array(
- '#header' => $header,
- '#rows' => $rows,
- '#empty' => $element['#empty'],
- '#attributes' => $element['#attributes'],
- );
- return drupal_render($table);
+ $element['#header'] = $header;
+ $element['#rows'] = $rows;
+
+ return $element;
}
/**
@@ -1541,7 +1536,7 @@ function form_process_tableselect($element) {
* The processed element.
*
* @see form_process_tableselect()
- * @see theme_tableselect()
+ * @see form_pre_render_tableselect()
*/
function form_process_table($element, FormStateInterface $form_state) {
if ($element['#tableselect']) {
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 7187666..4d134b5 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2705,9 +2705,6 @@ function drupal_common_theme() {
'render element' => 'element',
'template' => 'textarea',
),
- 'tableselect' => array(
- 'render element' => 'element',
- ),
'form_element' => array(
'render element' => 'element',
'template' => 'form-element',
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 10e291f..1205a9c 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -529,10 +529,13 @@ function system_element_info() {
'#input' => TRUE,
'#js_select' => TRUE,
'#multiple' => TRUE,
+ '#responsive' => TRUE,
+ '#sticky' => FALSE,
+ '#pre_render' => array('drupal_pre_render_table', 'form_pre_render_tableselect'),
'#process' => array('form_process_tableselect'),
'#options' => array(),
'#empty' => '',
- '#theme' => 'tableselect',
+ '#theme' => 'table__tableselect',
);
// Form structure.