Closed (duplicate)
Project:
Lost & found issues
Component:
Twig templates conversion (front-end branch)
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Sep 2012 at 20:27 UTC
Updated:
29 Apr 2014 at 14:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
andypostInitial fix, still
Twig_Error_Syntax: Unexpected tag name "_theme_table_cell" (expecting closing tag for the "for" tag defined near line 52) in "core/themes/stark/templates/theme.inc/table.twig" at line 52 in Twig_Parser->subparse() (line 165 of /var/www/d8twig/core/vendor/twig/twig/lib/Twig/Parser.php).Comment #2
jenlamptonthis is fixed in the latest chx sandbox
Comment #3
andypost@jenlampton Please point a link to this sandbox/branch
Comment #4
podarokwith #1770284: [META] Drupal 8 with twig issue queue cleanup
and Stark as admin theme on admin/modules
Twig_Error_Syntax: Unexpected character "$" in "core/themes/stark/templates/theme.inc/table.twig" at line 52 in Twig_Lexer->lexExpression() (line 285 of /var/www/podarok/drupal_8_theme_and_twig_sprint/core/vendor/twig/twig/lib/Twig/Lexer.php).
Comment #5
podaroktagging
looks like this will be nice documentation example for #1779402: Make how-to documentation update based on sprint practice
Comment #6
andypostStill need something to do with _theme_table_cell
Twig_Error_Syntax: The function "_theme_table_cell" does not exist in "core/themes/stark/templates/theme.inc/table.twig" at line 52 in Twig_Node_Expression_Function->compile() (line 28 of /var/www/d8twig/core/vendor/twig/twig/lib/Twig/Node/Expression/Function.php).Comment #7
podarok\ No newline at end of file
Comment #8
podaroklooks like we need decide and extend #1760468: [DX] Functions and filters in twig templates list of functions as described in Twig docs http://twig.sensiolabs.org/doc/advanced.html#functions
...
Comment #9
podarokpostponed till common decision about the way for feature adding new functions into twig #1760468: [DX] Functions and filters in twig templates
Comment #10
jenlampton_theme_table_cell has been moved to the preprocess function - and has no business being called from within a twig template :) We Certainly should not add it.
Also, there is no $ in table.twig. Please make sure you have the latest code. I replaced the pixelmord sandbox with the chx sandbox yesterday - so if you do a git pull you should get the latest versions of everything :)
Comment #11
podarokhttp://drupalcode.org/sandbox/pixelmord/1750250.git/blob/514cc820ff6b494...
Looks like really fixed @andypost
Comment #12
fabianx commentedThe preprocess code is totally broken.
Tables do not display at all currently.
That is critical, because other blocks cannot be tested.
psynaptic, could you take that one?
Comment #13
psynaptic commentedSure, I'll have a go at this tomorrow.
Comment #14
psynaptic commentedI got this working for headers, rows, and empty. Tables are not yet 100% complete but at least they are working to a good base level now.
http://drupalcode.org/sandbox/pixelmord/1750250.git/commit/c64567f79212c...
I need to figure out what to do about attributes as currently
throws an error:
It also needs testing on more tables, and other table features implementing. I'm happy to work on this some more but I'm done for today.
Comment #15
psynaptic commentedI fixed the attributes issue by converting them to the new Attribute system. I did a few test tables in a custom module and tested all the admin tables to ensure things work as expected and everything I've done so far is looking good. There are still other table features that need implementing, basically copying them from
theme_tabletotemplate_preprocess_tableand ensuring they work.http://drupalcode.org/sandbox/pixelmord/1750250.git/commit/c64567f79212c...
Comment #16
fabianx commentedI am adding the latest patch you applied to front-end here to use Dreditor to comment ...
Comment #17
fabianx commentedWe can either use _theme_table_cell in the preprocess or call it from within twig as sub-theme once table-cell.twig has been converted. That might be even faster, but that would need testing.
It would be nice in general if you could add some test code you are using to test this.
We will most probably need it when we try to get this patches into core.
You should be using always:
The {- is used to not create some white space and increases readability (imho).
Please see: http://twig.sensiolabs.org/doc/templates.html#whitespace-control
Thank you very much for your work so far. Looking forward to how you'll get the tablesort things in :-).
As this is functional now, moving to "major".
Comment #18
psynaptic commentedI was thinking that we should remove
_theme_table_celland replace it with a Twig template.I haven't written any "tests" per se, I've just created a module with tables so I can manually verify things work as expected.
Ok, sounds good. I didn't realise that hyphen was doing a trim, good to know.
To be honest, I have no idea how this works but I assume it just uses JS so it wouldn't need any structural changes.
Comment #19
fabianx commentedYes and it would be great to attach the module here to do manual testing as well.
Yes, only need to copy the code to the preprocess, no need for .twig changes.
Comment #20
psynaptic commentedAh, of course, not JS but another query.
Comment #21
anthonyR commentedThis commit breaks the front-end branch for me on admin/modules and admin/people. I used clean install and db.
I get the following error:
Fatal error: Class 'Drupal\Core\Template\ArrayIterator' not found in /Users/anthony/Sites/drupal_8_theme_and_twig_sprint/core/lib/Drupal/Core/Template/Attribute.php on line 132Comment #22
psynaptic commentedhttps://github.com/psynaptic/twig-tables
Comment #23
psynaptic commentedGot table sorting working:
http://drupalcode.org/sandbox/pixelmord/1750250.git/commit/39d93a187f57d...
I've pushed the tablesort example table to my twig-tables test module repo.
Comment #24
psynaptic commented#21: I created a core bug for it #1805776: Fatal error: Class 'Drupal\Core\Template\ArrayIterator' not found in core/lib/Drupal/Core/Template/Attribute.php
Comment #25
fabianx commentedBack to major now that front-end works again.
Comment #26
jenlamptonThere have been a lot of changes to theme_table in HEAD that we don't have yet in this sandbox. maybe we should hold off on doing any more here until we merge with head? See #1779136: Weekly - Merge Twig sandbox with latest HEAD
Comment #27
jenlampton@psynaptic we're going to need the new table stuff added into twig now that we've merged back together. Should I leave this to you since you have already started on it?
Comment #28
tostinni commentedThis code is still under heavy work, but I'd like to reference some bugs I just found: #1843724: Preprocess table cell errors;
Comment #29
psynaptic commentedSure, I'll try to find time to look at this. Right now I'm a bit swamped.
Comment #30
joelpittetI haven't merged any of this work yet but looking at fixing some of the obvious bugs. Here's a patch that:
* Makes sure $variables is & referenced in template_preprocess_table
* does the isset() part from #1843724
* changes the first $attributes to $table_attributes so it doesn't get mangled by the other $attribute arrays
* change $responsive to $is_responsive because there is another variable later called $responsive later down the function
* Pump $table_attributes onto $variables['attributes'] for the table to get them.
This doesn't fix everything bug gets the track a little straighter and would like to commit this and keep working on this if it helps out psynaptic?
Comment #31
joelpittetOk this patch gets things actually working in stark, but it doesn't play nice with theme_table because I needed another array for the template to spit out the row attributes and it's cells.
{% for cell in row.cells %}Also, I added in colgroup support to the twig template but Attribute is messing with me and adding to some classes to the cols but not all of them...
Was testing with the colgroup example from:
http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7
And it was the second colgroup's col class="funky" that wasn't rendering.
Give this a go and let me know your changes.
Comment #32
ry5n commentedEDIT: I'm having trouble testing this, with some inconsistent behaviour. Example:
I'm curious how you went about testing the table twig template against that example from the API docs, since I'd like to try that.
One super minor typo in the comment in theme.inc:2326
Comment #33
joelpittet@ry5n I just cheated & copied that example array right into the top of the preprocess function for colgroups. Should probably make some tests to help my sanity on that one! It took a while to get all the pieces gelling.
Also I think I have a logic error
if (!empty($headers) && !empty($rows)) {should just be
if (!empty($headers)) {To be consistent with what was there before. The sticky and responsive tests never really cared weather there are rows.
One thing that is bothering me and is taking all my urges not to change it is that if there are no rows, the empty message get's pumped into the rows. From a themer point of view it would be nice decide that the empty_message be placed instead of the table in most cases. But would still like the case available to count the columns(read by colspan count) so that the twig themers could reproduce this colspan version that is in core. That way you could check count(rows) in twig and there would sometimes be 1 because of the empty message as it is now. Does that make sense to anybody else but me? -itch fingers
Comment #34
joelpittetAdded a new feature branch to keep track of the changes:
Latest diff:
http://drupalcode.org/sandbox/pixelmord/1750250.git/blobdiff/f2937404046...
Commit:
http://drupalcode.org/sandbox/pixelmord/1750250.git/commit/f6da63dc43e31...
Comment #35
joelpittetBranch: twig-table-1778968
Latest changes:
http://drupalcode.org/sandbox/pixelmord/1750250.git/commitdiff/5d033b90b...
Diff from the branch start
http://drupalcode.org/sandbox/pixelmord/1750250.git/commitdiff/e1d9e49ff...
Commit:
http://drupalcode.org/sandbox/pixelmord/1750250.git/commit/5d033b90bd194...
Mostly removed all the duplicate parsing from theme_table and refactored the preprocess to work with both twig and theme_table
I did quite a bit of changes here, core hasn't done any theme.inc theme_table changes so nothing to merge from there.
Could someone have a look and see I am on the right path and not wasting my time?
My next step will be writing a bunch of fake tables to see if it's generating the correct output.
So far I have been using views
/admin/structure/viewsand people/admin/people?sort=asc&order=MemberforComment #36
joelpittetNext round, added theme_table_cell() to the mix to keep things consistant and make the theme_ functions act as close to the html.twig files as I can.
Now more with more stable! Please test and throw me your bugs.
Comment #37
steveoliver commentedFirst thing I notice...
Sort image source missing.
Comment #38
joelpittetThis is what "fixes" the second colgroup's
<col>missing attributes issue. Seems that in side the second colgroup loop the attributes have been popped out from the first scope. This may have to do with how{{ attributes.class }}removes it's class attribute from the next evaluation of{{ attributes }}Does anybody know where best to put this issue to make a stink about it?
is fixed by
Comment #39
joelpittetre #37 @steveoliver
Related to some preprocessing of the table image sorter... there's my take/issue
http://drupal.org/node/1860858#comment-6820284
Comment #40
joelpittetre #38 if anybody want's to try to reproduce this, here is how:
https://gist.github.com/4231241
I chucked the dump output in there to show that it's indeed in there, but getting popped off in the second round. I think this is an Attribute popping/Twig for loop context blocker.
Comment #41
steveoliver commentedI committed the patch from #36 (without the trailing whitespace it contained), just to get tables working for the moment.
There's no errors being thrown, but a few known issues:
<col>'s contain).In general, there's lots of cleanup that needs to be done to make the code more clear and understandable. Also, the API probably (I recommend) needs to change to keep all attributes in an 'attributes' or '#attributes' property instead of things like 'class' and 'colspan' being in their own top level properties for things like cells and headers.
Comment #42
steveoliver commentedSo here's where I'm at with addressing the concerns I posted in #41. Note: does not work. #needslove.
Comment #43
steveoliver commentedJust some notes on what I'm thinking with the code above:
Generally, I'm trying to stay away from declaring new variables, then setting their values back to the original variables unless necessary.
I'm also trying to use unique variable names to be clear about when we're working on header cells or row cells for example.
These top level variables should already have the right data in them, the data I don't think should be nested in 'cell'. Also, casting attributes to Attribute() right out of the gate, so we don't need to (remember to) convert them at the end of the function.
Really tried to make sense of the twig docblock by cleaning up verbiage and order. I know this is kinda a later (cleanup) task, but it helped me to understand what was/should be going on in preprocess.
Pretty much all just indentation fixes, I think.
That's about it for now.
Comment #44
joelpittetCommitted #38 for a temporary fix and added a comment to it's purpose for now.
Comment #45
joelpittet@steveoliver Attempting to give #42 love. I agree with the direction you are aiming for. Here are some patches that work, add the cleanup, plus got rid of the
//in the twig docblock and added a bit more to what you changed. Plus rolled in the temporary fix and removed some whitespace at the end of lines.The part that doesn't work is the theme stuff so I will dig deeper there...
Comment #46
joelpittetGetting a bit closer to your working #42, "the answer to life the universe and everything"
This fixes the th not getting responsive classes, removes
['cell']and gets rid of that _theme_table_cell and fix the classes for the active sorted table cellComment #47
joelpittetHave a peek at #45 and #46 for code cleanup and fixes
Comment #48
steveoliver commentedNice work, Joel. I went as far as I could with template_preprocess_table(), building on my earlier suggestions and your work from 45 and 46.
Attached is my latest (ready to commit as far as I'm concerned) plus the interdiff against your cumulative patches up to #46.
Gonna let someone else RTBC and commit this. c4rl, jen?
Comment #49
steveoliver commentedFabianx: Maybe you might know: I tried to set
$variables['attributes'] = new Attribute($variables['attributes'])here, and add classes to$variables['attributes']directly during preprocess. The only way I was able to get the table attributes to work was to cast to Attribute() at the bottom of _preprocess. Since I expect to be able to work with Attribute as an array, another set of eyes might notice I've done something wrong with attributes.This comment touches on the point(s) I made in earlier comments about overwriting and redefining variables using temporary variables. It made things hard to follow and I wonder if it may be dangerous when we might be wiping out data structures when all we need to do is be modifying them.
API Change? Rename this variable from 'empty' to 'empty_message'?
API CHANGE: Do we want to do this, so cell doesn't have just 'class', but 'attributes', which can include 'class' along with any others? If that's considered a feature, we don't need to, because it works as is.
Comment #50
joelpittetHere is a patch from #48, it fixes colspan (and the other attributes) missing from table cell and some notices due to headers not in table or empty message missing etc.
interdiff noob...
Last API change in #49 was removed in place of a bigger loop to get other attributes. It's nasty still but just an FYI. That's why colspan was missing...
Comment #51
joelpittetSomewhere in the patching I lost my fancy twig loop fix
Comment #52
steveoliver commentedJoel put a Colgroups test table in twig-tables module (/twig-tables path) now.
It seems
<col{{ col.attributes }}/>works fine.This patch leaves your funky loop handling out but cleans up indentation in the table.html.twig template.
Please test and lemme know.
Comment #53
steveoliver commentedOK, We've still got this issue to work out: #1867090: Nested Twig 'for' loops behaving strange, but I just committed this patch to front-end.
It works. :)
Comment #54
steveoliver commentedNotice I added this comment about the outstanding issue.
Comment #56
steveoliver commentedThis removes (2) of the (3) total instances of
theme()(theme('table_cell')) called in templates, as per #1842160: Consider appropriate usage of theme() from within Twig templates and #1842326: Merge _theme_table_cell() into theme_table().Comment #57
c4rl commentedI made some improvements to #56
I have:
* removed theme_table_cell()
* removed template_preprocess_table_cell()
* fixed hook_theme to remove table_cell
I also brought in most of the changes from this patch on #1842326: Merge _theme_table_cell() into theme_table(), but now that seems to be failing tests :(
I'll try to post a follow-up tomorrow.
Comment #58
c4rl commentedOops, forgot to post patch.
Also meant to mention: Why has the original theme_table() changed so much from HEAD? I didn't understand why, so this patch brings theme_table() to the current HEAD, plus the changes from #1842326: Merge _theme_table_cell() into theme_table() (currently failing tests -- as I said, I'll have a look at this tomorrow).
Comment #59
joelpittet@c4rl I may have missed something but the reason we have the theme_table_cell is to keep the markup out of PHP and in the template files. Did I miss a convo to this regard, while I was out?
Comment #60
c4rl commentedFYI, the attached interdiff is with respect to #56, not #58.
@joelpittet #59 Can you be more specific? That is, reference lines of code whereby _theme_table_cell() is necessary, and how the attached patch does not fulfill those goals. I believe, as I have discovered, if you examine _theme_table_cell() in 8.x HEAD you will see that it is simply a helper callback and its utility outside of theme_table() is not clear nor necessary.
With some revisions, #1842326: Merge _theme_table_cell() into theme_table() has passed tests. I have included the changes from that patch in revisions from steveoliver's #56. You will notice that theme_table() (the original theme function) is modified in this patch to match 8.x HEAD. It is not clear to my why theme_table differs in the sandbox vs 8.x HEAD since we should be only creating preprocessors for the sake of conversion in the sandbox, and handling modifications to the original markup and APIs in the core project. Let me know if I am missing anything, or if this approach seems unclear.
Comment #61
joelpittet@c4rl #17 and #18 were people were talking about it and at #31 I did the first pass.
The intent was to remove HTML tags from being built in preprocess functions or any PHP functions for that matter. It did offer some theming flexibility, albeit minor, but mostly for consistency and cleanliness.
Comment #62
c4rl commentedSure, I agree with you. That's where we want to be with preprocessors. My point is this: _theme_table_cell() isn't necessary in either theme_table() (the old function) nor template_preprocess_table() (the new function). _theme_table_cell() just provided a few lines of HTML, that's it. Please review the API page and have a look look at the patch in #60, namely:
_theme_table_cell() is just a shortcut to write a few lines of HTML (and, IMHO, an example of when DRY becomes an anti-pattern). So, the patch in #60 does the following:
* In theme_table() refactors calls to _theme_table_cell() to simply mirror its functionality in theme_table(). theme_table() is already concatenating strings together, and will continue to do so until we replace it outright with template_preprocess_table() in the final patch to HEAD. The sandbox has both for the sake of conversion.
* In table.html.twig, provides the markup I pasted in the codeblock above. Preprocessors, in principle, should not contain HTML, as we both acknowledged.
Comment #63
joelpittet@c4rl, Ok I think I am getting the pieces sorted a bit better now, thanks. The reason behind the theme_table_cell() was for some backward compatibility issues when the twig engine wasn't on, I removed the internal _theme_table_cell() and just replaced it with theme_table_cell(). I noticed you removed the theme_table_cell() in your patch so I was like OH NOES it will break in phptemplate! But now I see where all the pieces landed, the theme_table has the theme_table_cell function stuff embedded and you pulled the th/td into the table. Much better then what I thought happened!
Comment #63.0
joelpittetUpdated issue summary.
Comment #64
sun#1939008: Convert theme_table() to Twig