Comments

markhalliwell’s picture

Issue summary: View changes

Updated issue summary.

stevector’s picture

Status: Active » Needs review
StatusFileSize
new539 bytes

Here'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".

stevector’s picture

This patch also removes the preparation of the variable from template_preprocess_node().

stevector’s picture

Issue summary: View changes

Updated issue summary.

Status: Needs review » Needs work

The last submitted patch, trans-tag-replacing-submitted-2047095-2.patch, failed testing.

markhalliwell’s picture

Status: Needs work » Closed (duplicate)

This 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 $submitted from the preprocess layer.

fabianx’s picture

Status: Closed (duplicate) » Needs review

Back to CNR as the other issue is still under heavy discussion and we want this change in - regardless.

fabianx’s picture

fabianx’s picture

I want to see what testbot says :).

Status: Needs review » Needs work

The last submitted patch, trans-tag-replacing-submitted-2047095-2.patch, failed testing.

markhalliwell’s picture

Looks like rdf_preprocess_node() wraps $submitted to add additional RDF meta data. Thoughts on how to fix this?

berdir’s picture

node.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.

fabianx’s picture

Yup, we still need the username for now, but other things are possible now.

scor’s picture

chrisfromredfin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.23 KB

The 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.

Status: Needs review » Needs work

The last submitted patch, replace-submitted-by-2047095-13.patch, failed testing.

scor’s picture

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.

Yes, @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:

function template_preprocess_node(&$variables) {
...
  $username = array(
    '#theme' => 'username',
    '#account' => $node->getAuthor(),
    '#link_options' => array('attributes' => array('rel' => 'author')),
  );
  $variables['name_array'] = $username;
  $variables['name_rendered'] = drupal_render($username);

in node.html.twig:

      <p class="submitted_test">
      {% trans %}
        Submitted by as array {{ name_array|passthrough }}
        Submitted by rendered {{ name_rendered|passthrough }}
      {% endtrans %}
      </p>

The second instance in twig works, but the first generates a "Array to string conversion" warning.

scor’s picture

It seems this doesn't work because of the trans tags. If I remove the trans tags and the passthrough, it works:

      <p class="submitted_test">
        Submitted by as array {{ name_array }}
        Submitted by rendered {{ name_rendered }}
      </p>

So the challenge now is to find out to use render arrays in twig inside trans tags.

fabianx’s picture

As a work-around you could do for now (until this is fixed, to test if everything else works properly):

{% set name = render_var(name) %}

This should work as work-around and allow tests to pass until we fix it.

chrisfromredfin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.58 KB

The 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.

chrisfromredfin’s picture

Taking 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 69

When 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.

Status: Needs review » Needs work

The last submitted patch, replace-submitted-by-2047095-18.patch, failed testing.

chrisfromredfin’s picture

After spending some time with this today, mostly in a debugger, the issue seems to be that in the source that Twig compiles we get:

      <p class=\"submitted\">
      ";
            // line 92
            $context["date"] = twig_render_var($this->getContextReference($context, "date"));
            // line 93
            echo "      ";
            $this->getContextReference($context, "name") = twig_render_var($this->getContextReference($context, "name"));
            // line 94
            echo "      ";
            echo t("Submitted by !name on !date", array("!name" => $this->getContext($context, "name"), "!date" => $this->getContext($context, "date"), )) . '
<!-- TRANSLATION: "Submitted by !name on !date" -->
';
            // line 97
            echo "      </p>

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:

$context['name'] = ...

(rather than)...

this->getContextReference($context, "name") = 

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:

{% set x = name %}

...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):

  $username = array(
    '#theme' => 'username',
    '#account' => $node->getAuthor(),
    '#link_options' => array('attributes' => array('rel' => 'author')), 
  );
chrisfromredfin’s picture

Issue summary: View changes

Updated issue summary.

andypost’s picture

+++ b/core/modules/node/node.module
@@ -657,7 +664,6 @@ function template_preprocess_node(&$variables) {
   $submitted = \Drupal::config('node.type.' . $node->bundle())->get('settings.node.submitted') ?: TRUE;
   if ($submitted) {
     $variables['display_submitted'] = TRUE;
-    $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
     if (theme_get_setting('features.node_user_picture')) {

This 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

andypost’s picture

scor’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (outdated)

$submitted was removed from the template in #2047095: Remove $submitted from node templates.