Squeezed into #1260860-45: Rework language list admin user interface...

Problem

  • Link lists are hardly extensible and alterable.

Example

  1. You have a table, with Operations column.
  2. You have one or more modules integrating with that table, adding operations.
  3. You have a renderable structure, but all the links get stacked into an odd #links property of a single element.
  4. Say hello to array_splice(), array_slice(), array_search(), array_pop(), and array_unshift()! Your only way to inject a link at a certain position.

Solution

  • Introduce #type 'links'.
    1. Renders sub-elements of #type 'link', 'markup', or whatnot first, and as usual. (respecting #weight, #ajax, and whatever else you want to do)
    2. Takes the rendered #children of each sub-element and turns them into items of an item list.
    3. Profit.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul’s picture

sub

sun’s picture

So what this patch kinda cries for is a #pre_theme[_wrappers] facility in drupal_render().

Essentially, we want drupal_render() to run on the renderable (sub-)elements as usual.

But then, instead of outputting the results, do some quick shuffling on the rendered #children of the sub-elements, and pass the ultimate result along to an already existing theme function.

I could imagine that this technique could become kind of a pattern to expose a theme function not only as theme function, but also as a #type that works with renderable arrays as input.

Jacine’s picture

Hell yes! :D I love love love this idea.

sun’s picture

FileSize
2.86 KB

Wanted to know how it would look like with #pre_theme_wrappers, so here we go.

To be compared with #0.

sun’s picture

FileSize
2.87 KB

And, FWIW, a funky #pre_render approach. :)

To be compared with #4 and #0.

dozymoe’s picture

One other option is in http://drupal.org/node/1295958. Dunno.

jwilson3’s picture

@dozymoe, I like generalized solutions as much as anyone, but as you point out in comment #10, on #1295958: Arguments to theme as renderable array in a render array. Allow better nesting of html element., the code there could really lend itself to noticable performance issues for deeply nested use of render arrays.

On the other hand, in the case of links, where often lists of links are multi-level -- I'm wondering how this solution differs from that one. It looks potentially like by limiting this to a single #links option, second and third level links would have to be pre-rendered into html as their own list of links, before being added to the parent (which well could solves the performance problem of nested arrays of hell).

jwilson3’s picture

There is really good info here. Tagging for visibility and consideration in theme cleanup

dawehner’s picture

FileSize
8.71 KB

Let's fix the @todo in the patch

Status: Needs review » Needs work

The last submitted patch, drupal-1300744-9.patch, failed testing.

jibran’s picture

jibran’s picture

Status: Needs work » Needs review
FileSize
1.19 KB
2 KB

node_page_default is removed in #1806334-168: Replace the node listing at /node with a view so I exclude it form the patch. Added new @todo.

thedavidmeister’s picture

Status: Needs review » Needs work

The patch no longer applies for me:

error: patch failed: core/modules/system/system.module:545
error: core/modules/system/system.module: patch does not apply

star-szr’s picture

Assigned: sun » Unassigned
Issue tags: +Needs reroll
jibran’s picture

Status: Needs work » Needs review
FileSize
1.89 KB

reroll

Eric_A’s picture

Status: Needs review » Needs work

theme_item_list() does not render the #children property, so it's not suitable for #theme_wrappers.

Apart from that I think we should be moving this towards the approach from #2025629: [meta] Ensure that all #theme/#theme_wrappers hooks provided by core are associated with a sensible, re-usable element #type.

Eric_A’s picture

Assigned: Unassigned » Eric_A
Category: feature » task

Working on this.

Eric_A’s picture

Assigned: Eric_A » Unassigned
Status: Needs work » Needs review
FileSize
2.84 KB
Eric_A’s picture

Removing "Needs reroll" tag.

Eric_A’s picture

Issue tags: -Needs reroll

And now for real.

Eric_A’s picture

Status: Needs review » Needs work

The focus of #2025629: [meta] Ensure that all #theme/#theme_wrappers hooks provided by core are associated with a sensible, re-usable element #type is on existing render arrays that declare a '#theme' property but not a type. I'm going to compile a list of files to deal with.
Replacing direct calls to theme() with render arrays is dealt with elsewhere and should probably be left out here.

Eric_A’s picture

Status: Needs work » Needs review
FileSize
4.24 KB
$ grep -R --files-with-matches "'#theme' => 'links'" core
core/modules/block/lib/Drupal/block/Plugin/PluginUI/BlockPluginUI.php
core/modules/node/lib/Drupal/node/Plugin/views/area/ListingEmpty.php
core/modules/system/lib/Drupal/system/Tests/Theme/FunctionsTest.php
core/modules/system/tests/modules/ajax_test/ajax_test.module
core/modules/views/views.api.php
core/update.php

From the above files only views.api.php was left untouched.

Eric_A’s picture

FileSize
4.54 KB
3.21 KB

Removed the #theme property.

thedavidmeister’s picture

Status: Needs review » Needs work

The patch in #25 looks good from the perspective of #2025629: [meta] Ensure that all #theme/#theme_wrappers hooks provided by core are associated with a sensible, re-usable element #type.

I don't think it addresses @sun's concerns in the issue summary and subsequent comments though.

The very fist patch, in the issue summary introduces a new theme function that can be used in #theme_wrappers - although I'd prefer to call it theme_links_wrapper than theme_wrap_links to be more consistent with similar functions elsewhere. Could we try to incorporate that idea, or the #pre_render function proposed in #5 into #25?

I don't think we should be looking into anything like #2 and #4 here though.

The main reservation I have with the idea of any kind of processing step that comes after the render step (like #pre_theme_wrappers) is that I don't see (and nobody has ever explained to me) how that processing could ever be compatible with the "drillability" idea #2008450: Provide for a drillable variable structure in Twig templates, in the same vein as #2009132: Remove #pre_render and #post_render from drupal_render() as it prevents proper Twig drillability.

At this point I'm not sure if that means "drillability" is just a fantasy we've made up recently or a criticism of arbitrarily interleaving multiple render and processing steps.

Regardless, IMO this issue shouldn't be introducing any new rendering/processing steps into drupal_render(), that kind of thing needs discussion, tests written and to have its own issue. If we can address @sun's problems with #theme_wrappers or #pre_render then great, otherwise I think #25 will have to do as a first "baby step" for now and we can split out some follow-up issues to address whatever is getting in the way.

thedavidmeister’s picture

Status: Needs work » Needs review

Or... maybe we shouldn't be trying to render the individual links at all because in general I believe we're supposed to be as lazy as possible about calling drupal_render() so we can keep our data as structured data for as long as possible rather than "flattening" them into strings...

In which case, #25 is probably exactly what we should be doing here.

Eric_A’s picture

Related: #311011: Replace links.html.twig with item-list--links.html.twig. Haven't had the time to really look into it, but fixing that one first might get us towards a much, much more interesting implementation of #type links.

jibran’s picture

#25: 1300744-25.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1300744-25.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

Pinolo’s picture

Assigned: Unassigned » Pinolo
Issue summary: View changes

Working on this one during today's DrupalItalia code sprint

kmox83’s picture

FileSize
6.27 KB

Removed the part of the patch related to the files which have been removed from the core (Issue #2056513). Extended the patch to all the classes in core which uses the links.

kmox83’s picture

Status: Needs work » Needs review

Related to the comment #32

Pinolo’s picture

Assigned: Pinolo » Unassigned
neclimdul’s picture

Looking good guys.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

I think you missed one though.

core/modules/system/system.module:547:    '#theme' => 'links',
neclimdul’s picture

Status: Reviewed & tested by the community » Needs work

that wasn't need work... I miss the preview button.

kmox83’s picture

Should it be changed back to Reviewed & tested by the community?

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community

Yes, sorry. Everything looks good.

sun’s picture

Status: Reviewed & tested by the community » Needs work

mmm, this patch does not really resolve the problems outlined in the OP. :-/

To my knowledge, the Twig team also wants to get rid of theme_links(), because that is actually just an (item) list in reality, and it doesn't make sense to have a generic list template and another one for "a list of links".

→ A new #type links should not only resolve the problems stated in the OP, but also incorporate the fact that each rendered child is just a list item; i.e., the #pre_render should drupal_render() each child element and then pass off the rendered children into theme_item_list().

thedavidmeister’s picture

A new #type links should not only resolve the problems stated in the OP, but also incorporate the fact that each rendered child is just a list item; i.e., the #pre_render should drupal_render() each child element and then pass off the rendered children into theme_item_list().

Item lists are a Twig template not a theme function now. Could we avoid touching drupal_render() in #pre_render if at all possible?

neclimdul’s picture

This patch actually abstracts the theme calls in all theses places into the #type so it could have a follow up to replace how its rendered or makes removing theme_links easier by having a central location. I still think this is RTBC.

thedavidmeister’s picture

Well, we need some kind of consensus, but it sounds like either way we're due for an issue summary update.

star-szr’s picture

lauriii’s picture

Version: 8.0.x-dev » 8.1.x-dev
Category: Task » Feature request
Status: Needs work » Postponed

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now 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.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.