Commit 28ef6b28 authored by alexpott's avatar alexpott

Issue #2152227 by JeroenT, joelpittet, steinmb, steveoliver, hussainweb,...

Issue #2152227 by JeroenT, joelpittet, steinmb, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_tableselect() to #theme table__tableselect.
parent 17fcc164
...@@ -1348,18 +1348,19 @@ function form_process_container($element, FormStateInterface $form_state) { ...@@ -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 * Adds a column of radio buttons or checkboxes for each row of a table.
* An associative array containing: *
* - element: An associative array containing the properties and children of * @param array $element
* the tableselect element. Properties used: #header, #options, #empty, * An associative array containing the properties and children of
* and #js_select. The #options property is an array of selection options; * the tableselect element. Properties used: #header, #options, #empty,
* each array element of #options is an array of properties. These * and #js_select. The #options property is an array of selection options;
* properties can include #attributes, which is added to the * each array element of #options is an array of properties. These
* table row's HTML attributes; see theme_table(). An example of per-row * properties can include #attributes, which is added to the
* options: * table row's HTML attributes; see table.html.twig. An example of per-row
* @code * options:
* @code
* $options = array( * $options = array(
* array( * array(
* 'title' => 'How to Learn Drupal', * 'title' => 'How to Learn Drupal',
...@@ -1385,15 +1386,12 @@ function form_process_container($element, FormStateInterface $form_state) { ...@@ -1385,15 +1386,12 @@ function form_process_container($element, FormStateInterface $form_state) {
* '#options' => $options, * '#options' => $options,
* '#empty' => t('No content available.'), * '#empty' => t('No content available.'),
* ); * );
* @endcode * @endcode
* *
* @ingroup themeable * @return array
* The processed element.
*/ */
function theme_tableselect($variables) { function form_pre_render_tableselect($element) {
$element = $variables['element'];
$table = array(
'#type' => 'table',
);
$rows = array(); $rows = array();
$header = $element['#header']; $header = $element['#header'];
if (!empty($element['#options'])) { if (!empty($element['#options'])) {
...@@ -1433,7 +1431,7 @@ function theme_tableselect($variables) { ...@@ -1433,7 +1431,7 @@ function theme_tableselect($variables) {
// checkboxes/radios in the first table column. // checkboxes/radios in the first table column.
if ($element['#js_select']) { if ($element['#js_select']) {
// Add a "Select all" checkbox. // 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'))); array_unshift($header, array('class' => array('select-all')));
} }
else { else {
...@@ -1442,14 +1440,11 @@ function theme_tableselect($variables) { ...@@ -1442,14 +1440,11 @@ function theme_tableselect($variables) {
array_unshift($header, ''); 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) { ...@@ -1541,7 +1536,7 @@ function form_process_tableselect($element) {
* The processed element. * The processed element.
* *
* @see form_process_tableselect() * @see form_process_tableselect()
* @see theme_tableselect() * @see form_pre_render_tableselect()
*/ */
function form_process_table($element, FormStateInterface $form_state) { function form_process_table($element, FormStateInterface $form_state) {
if ($element['#tableselect']) { if ($element['#tableselect']) {
......
...@@ -2705,9 +2705,6 @@ function drupal_common_theme() { ...@@ -2705,9 +2705,6 @@ function drupal_common_theme() {
'render element' => 'element', 'render element' => 'element',
'template' => 'textarea', 'template' => 'textarea',
), ),
'tableselect' => array(
'render element' => 'element',
),
'form_element' => array( 'form_element' => array(
'render element' => 'element', 'render element' => 'element',
'template' => 'form-element', 'template' => 'form-element',
......
...@@ -529,10 +529,13 @@ function system_element_info() { ...@@ -529,10 +529,13 @@ function system_element_info() {
'#input' => TRUE, '#input' => TRUE,
'#js_select' => TRUE, '#js_select' => TRUE,
'#multiple' => TRUE, '#multiple' => TRUE,
'#responsive' => TRUE,
'#sticky' => FALSE,
'#pre_render' => array('drupal_pre_render_table', 'form_pre_render_tableselect'),
'#process' => array('form_process_tableselect'), '#process' => array('form_process_tableselect'),
'#options' => array(), '#options' => array(),
'#empty' => '', '#empty' => '',
'#theme' => 'tableselect', '#theme' => 'table__tableselect',
); );
// Form structure. // Form structure.
......
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