Move all the preprocessing of the table funtion to a preprocess function in order to simplify theme_table() and make it more themer-friendly.

The structure given to theme_table will always have the data key filled in. Everything else seems to work fine, checked the module page and the content overview one. Sorter and responsive still works. theme_table is now 73 loc, it was previously 169 loc and it's just a couple of foreachs.

It needs some docblock and probably should be moved somewhere else in the file but it works™.

CommentFileSizeAuthor
core-preprocess_table.patch10.59 KBnod_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Title: Add preprocess to table_theme function to simplify it » Add preprocess to theme_table function to simplify it

oups :p

Lars Toomre’s picture

The theme_table() functions needs a docblock.

steveoliver’s picture

Status: Needs review » Postponed

Let's postpone this on #1778968: Convert theme_table to Twig getting into core?

sun’s picture

Status: Postponed » Needs work
Issue tags: +API clean-up, +theme system cleanup

mmm, I'm a little scared by doing such fundamental refactoring as part of a monster branch/patch that will change a ton of other things.

Furthermore, I looked at the patch in #1778968: Convert theme_table to Twig and it looks like it doesn't really improve the situation with theme_table() - the total amount of conditional and custom processing per table/thead/tbody/row/column/cell is only increased, it's partially moved into the templating layer, and the sandbox-committed code contains a range of @todos that were not addressed.

Now that #80855-90: Add element #type table and merge tableselect/tabledrag into it has landed, I think we can and should move forward with this clean-up here. (Also note the follow-up issues mentioned over in comment #90.)

In essence, most of theme_table() should be moved into a template_preprocess_table() that performs all of the heavy plumbing, so that theme_table() itself turns into a couple of pure + trivial foreach loops that render the individual parts. In terms of complexity, theme_table() (as well as table.twig.html) should look almost identical in the end and should not contain any special conditions or manual processing in the default theme implementation anymore.

sun’s picture

Issue summary: View changes
Parent issue: » #1939008: Convert theme_table() to Twig
sun’s picture

Status: Needs work » Closed (duplicate)