Problem/Motivation

When node and comment links are built the links are first passed through drupal_pre_render_links(), which messes with the render array in a way that is unexpected by the themer.

When you are adding links they have this form:

<?php
array(
  '#theme' => 'links__node',
  '#pre_render' => array(
    'drupal_pre_render_links',
  ),
  '#attributes' => array(
    'class' => array(
      'links',
      'inline',
      'post-links',
    ),
  ),
  'node' => array(
    '#theme' => 'links__node__node',
    '#links' => array(),
    '#attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  ),
  'comment' => array(
    '#theme' => 'links__node__comment',
    '#links' => array(
      'comment-add' => array(
        'title' => 'Add new comment',
        'attributes' => array(
          'title' => 'Share your thoughts and opinions related to this posting.',
        ),
        'href' => 'node/126',
        'fragment' => 'comment-form',
      ),
    ),
    '#attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  ),
)
?>

Now looking at that I would assume I could override the links function with THEMENAME_links__node__comment(), however much to my confusion it doesn't work.

After a bit of investigation I realise that drupal_pre_render_links() is moving the #links from the child links arrays into the parent one, which has the theme suggestion of links__node instead, but it doesn't actually render the child structures and marks them as #printed so that links__node__comments and other similar ones are never called.

This is unusual.

Proposed resolution

Possible solutions are:

  1. Change the way links are added (change the structure of the original links array), so that this moving links around is not necessary.
  2. Properly render the child render arrays so from the themer's point of view everything is working as expected.
  3. Change the child arrays' #theme value to be links__node, seeing as that is how they will actually be themed in the end. Although in this case there is nothing stopping modules from adding their own custom links with their own custom theme suggestion (like links__node__mymodule) and then wondering why they can't override that. (I don't think this really properly addresses the problem.)

Comments

rooby’s picture

I noticed this in D7 but it seems to also be a D8 problem.

joelpittet’s picture

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

May want to close this but drupal_pre_render_links() doesn't exist in D8.

Really don't follow the issue summary in this.

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Issue tags: +Needs backport to D7

It exists in Drupal 8 for me :)

https://api.drupal.org/api/drupal/core!includes!common.inc/function/drup...

I think what's described here is the documented, expected behavior of the function though. If you're rendering the whole list in one place, you need to get one list in the end, so multiple theme functions (each producing their own separate list) can't be called. They are only called if you choose to render a part of the array separately (i.e. to pull it out and render it as its own list).

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.

joelpittet’s picture

Sorry must have had a filter on my search or something, thanks @catch

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
catch’s picture

Status: Active » Closed (works as designed)

I think this is by design. A general modernisation of node links would be good, however there are other issues (somewhere) dealing with that.