Closed (outdated)
Project:
Drupal core
Version:
11.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
21 Jul 2013 at 16:47 UTC
Updated:
12 May 2024 at 03:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #0.0
markhalliwellUpdated issue summary.
Comment #1
stevectorHere's a patch. I found that the twig selectors didn't exactly match the example at https://drupal.org/node/1927584#summary-proposed-resolution
The file needed "node.author.name" instead of "author.name" and "date" instead of "node.date".
Comment #2
stevectorThis patch also removes the preparation of the variable from template_preprocess_node().
Comment #2.0
stevectorUpdated issue summary.
Comment #4
markhalliwellThis is actually just a dup of #2004252: node.html.twig template. I misread the title, didn't see the "templates" part. Thought it was just removing
$submittedfrom the preprocess layer.Comment #5
fabianx commentedBack to CNR as the other issue is still under heavy discussion and we want this change in - regardless.
Comment #6
fabianx commented#2: trans-tag-replacing-submitted-2047095-2.patch queued for re-testing.
Comment #7
fabianx commentedI want to see what testbot says :).
Comment #9
markhalliwellLooks like
rdf_preprocess_node()wraps$submittedto add additional RDF meta data. Thoughts on how to fix this?Comment #10
berdirnode.author.name, as nice as it looks, is a) not safe (not sure if that's a problem?) and b), not the right thing to use. Has to be .username, which should trigger getUsername().
Also, this is a problem with makin those fields quickedit-able, which is going in a different direction, make sure you check this with @WimLeers/@effulgentsia.
Comment #11
fabianx commentedYup, we still need the username for now, but other things are possible now.
Comment #12
scor commented#1706612: remove 'submitted' variable in templates for ease of theme development was marked as duplicate
Comment #13
chrisfromredfinThe attached patch removes the submitted by from template_preprocess_node and adjusts node.html.twig, as #2 does. It makes adjustments to the twig variables to keep up with the times.
In addition, it replaces the submitted by date by wrapping it in an HTML5 time element. We probably want to do this part in template_preprocess_node instead, the more we think about it. Even if we do it in template_preprocess_node, it would be nice to be able to pass a render array down the chain so that here in rdf.module we don't need to re-call drupal_render.
Comment #15
scor commentedYes, @cwells and I were trying to generate $variables['date'] as a render array in template_preprocess_node() and keep it a render array as long as possible until it reaches the Twig layer. The advantage is that other modules can alter the render array and add attributes in the case of rdf_preprocess_node(). This is basically what the Twig docs say.
in node.module:
in node.html.twig:
The second instance in twig works, but the first generates a "Array to string conversion" warning.
Comment #16
scor commentedIt seems this doesn't work because of the trans tags. If I remove the trans tags and the passthrough, it works:
So the challenge now is to find out to use render arrays in twig inside trans tags.
Comment #17
fabianx commentedAs a work-around you could do for now (until this is fixed, to test if everything else works properly):
This should work as work-around and allow tests to pass until we fix it.
Comment #18
chrisfromredfinThe following patch converts date to a render array, then the RDF module just adds on its property to the attributes; then the node.html.twig uses Fabianx's workaround from #17 above.
The workaround in #17 doesn't work so well when converting the username to a render array, so I will have to dig deeper on that, and I will try to submit again. But in the meantime, here's the approach for date.
Comment #19
chrisfromredfinTaking it from the patch in #18, if I take the same approach and simply remove the drupal_render call around username, I can get it passed all the way down into twig as an array, which is good.
However, when I try to {% set name = drupal_render(name) %} I end up with output that just dies partway through, and the following PHP error:
PHP Fatal error: Can't use method return value in write context in .../core/lib/Drupal/Core/Template/TwigEnvironment.php(87) : eval()'d code on line 69When it tries to load the template, there's obviously some kind of error happening there. I tried to debug it in twig_render_var, but I couldn't fully make sense of it without a step debugger. I tried to just print_r($var) there and failed (out of memory with a 256M limit). I'm hoping someone might have some insight about this error before next week; otherwise I will fire up xdebug and see if I can figure out what's going wrong.
Comment #21
chrisfromredfinAfter spending some time with this today, mostly in a debugger, the issue seems to be that in the source that Twig compiles we get:
My HUNCH is that the // line 92 and // line 93 should really look a lot more similar. That is, I think for the "name" variable that line should just start as:
(rather than)...
I tried a workaround Fabianx suggested, which was to try to set it to a temporary variable first, or to reassign via temp variables. What that led me to find, then, is that basically if I try to do so much as:
...then I get the error (the code compiles that way). It seems like setting that particular variable / render array causes the error. With that said, this is the exact same approach I've taken with the date variable (see patch in 18 above) and that one works perfectly smooth. My next approach was maybe to try with a third, neutral render array (like theme_picture) and see if that one works or dies.
I'm wondering if the Twig parser/processor is giving some sort of special treatment to the username variable, specifically, or if there's something that's missing in the preprocess_node setup of the username variable (which currently looks like):
Comment #21.0
chrisfromredfinUpdated issue summary.
Comment #22
andypostThis should be changed too according related #2053461-33: Node type settings such as published state, promoted state, create revision and author information cannot be turned off
The node_type entity could not exist so 'display_submitted' also should be used in template
Comment #23
andypostComment #24
andypostproper issue
Comment #25
scor commentedI believe #2226493: Apply formatters and widgets to Node base fields would help us here.
Comment #39
quietone commented$submitted was removed from the template in #2047095: Remove $submitted from node templates.