Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
create preprocess func + template file, add Attribute
theme func: theme_user_admin_roles
Comment | File | Size | Author |
---|---|---|---|
#5 | convert_theme_user_admin_roles-1819414-5.patch | 1.71 KB | vlad.dancer |
#1 | convert_theme_user_admin_roles-1819414-1.patch | 3.03 KB | vlad.dancer |
Comments
Comment #1
vlad.dancerThere are now problems with cell classes and table id because preprocess_table doesn't handle this.
So at this point patch is like scratch for future development, although it is working but doesn't apply tabledrag.
Comment #2
merdekiti CreditAttribution: merdekiti commentedComment #3
merdekiti CreditAttribution: merdekiti commentedSorry, I have changed the status of the task by a mistake. Changed back
Comment #4
drupalway CreditAttribution: drupalway commentedI believe you should change it to $rows[] = array('data' => $row, 'attributes' => array('class' => array('draggable')));
Cell attributes should be handled by template_preprocess_table(&$variables), core/includes/theme.inc
Comment #5
vlad.dancerFixes for comment #4 + renamed from "user_preprocess" to "template_preprocess"
Comment #6
drupalway CreditAttribution: drupalway commentedLooks good for me!
Comment #7
podarokthanks!
commited / pushed to front-end
Comment #8
jenlamptonIt looks like the template is missing from front-end, so re-applying patch.
Also, some notes:
As a general rule, we are not calling theme() functions from the preprocess layer. Instead we include the template file
table
directly from this new template. This will make it much easier for theme devs to find where the code they want to change is coming from.The theme_table function (or template) needs the variables
header
,rows
, andattributes
, so we expose those in preprocess here so they can be passed straight through to the table.html.twig file. Then we also need to calltemplate_preprocess_table()
from our preprocess function, to make sure that the table variables gets formatted correctly before being passed to that template.Also, attributes need to use the new Attribute class.
I'm going to make these changes, test, and commit this file.
Comment #9
jenlamptonthis is what the template now looks like:
feel free to check the changes in preprocess too, if you are curious.
Tested and pushed. marking as fixed.
Comment #10
vlad.dancerOk. I got this rule. It would be nice to note this rule in template converting doc.
Comment #11
decafdennis CreditAttribution: decafdennis commentedI understand the reasoning here, but it seems to me this approach doesn't work from a technical point of view.
What if my module implements:
Then my preprocess function will get bypassed with the approach above. Calling
template_preprocess_table()
directly is kind of a hack and is only meant to be called by the theming internals. Also, I want to point out that behavior will be different with this approach vs. usingtheme()
.Another situation where this "general rule" does not work is when you want to incorporate not one, but two or more arbitrary templates in your template, e.g.:
How do you handle that with the approach above?
I propose that this rule gets revised and/or another solution for the actual implementation of it is sought.
Comment #12
decafdennis CreditAttribution: decafdennis commentedComment #12.0
decafdennis CreditAttribution: decafdennis commentedUpdated issue summary.