Problem/Motivation
We have two very similar functions in Durpal theme_links and theme_item_list. Both of these functions loop through a set of items, and create a HTML list. This creates twice as much code to maintain, and two separate, nearly identical, things to keep up to date.
The plan is to use theme_links()
when a title and/or wrapper div is necessary, and theme_links()
will call theme('item_list')
to generate the list of items within. In turn, theme_item_list()
will not contain a wrapper div or title anymore.
Proposed resolution
This means we will need to update core to use theme_links()
) any time a title or wrapper div is necessary, and may need to
- Clean up or code so we are not passing in
'title' => NULL,
to theme_item_list() that will no longer accept a title - Move the titles from item_list into a #prefix on the render element
- Remove other weirdness in our code to make markup consistent
- Update tests to test for the new markup insted of old
Remaining tasks
There are eighty-three (83) instances of 'item_list' in core. Below is a list of *only* the ones that will need to be updated (since they require either a title or a surrounding div tag)
List of all instances of calls to theme('item_list') or render arrays with '#theme' => 'item_list' where a title or wrapper div is warranted
Location of item_list call | Call theme('links')? | why | Code changes (this patch) |
---|---|---|---|
core/authorize.php | YES | has title | replace item_list with links |
core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php | NO | Remove 'title' => NULL, |
|
core/includes/theme.maintenance.inc | NO | not links | move heading into #prefix on render element |
core/modules/node/node.module | YES | has title | replace item_list with links |
core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module | YES | has title | replace item_list with links |
core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php | NO | $form['analysis'] needs to be updated to add the form-item class as attributes, no extra div plz |
|
core/modules/views/views.theme.inc | NO | Remove '#title' => NULL, |
|
core/update.php | NO | not links | move title into #prefix on render element |
User interface changes
None.
API changes
None.
Related Issues
#311011: Replace links.html.twig with item-list--links.html.twig
#1842140: Remove title and wrapper div from item-list.html.twig
Comment | File | Size | Author |
---|---|---|---|
#70 | interdiff.txt | 737 bytes | Manuel Garcia |
#70 | replace_calls_to-2032645-70.patch | 8.94 KB | Manuel Garcia |
#67 | replace_calls_to-2032645-67.patch | 8.99 KB | joelpittet |
#67 | interdiff.txt | 3.3 KB | joelpittet |
#61 | 2032645-replacing_item_list_with_links-60.patch | 9.02 KB | piyuesh23 |
Comments
Comment #0.0
jenlamptonthings to change
Comment #1
jenlamptonSince there are only 5 instances of theme calls that need to be changed from 'item_list' to 'links' this does not need to be a meta issue, it can all be done in one patch.
Comment #1.0
jenlamptoncleanup
Comment #2
jenlamptonalso, tagging
Comment #3
jenlamptonclarification :)
Comment #3.0
jenlamptonupdate
Comment #3.1
jenlamptoncleanup
Comment #3.2
jenlamptoncleanup
Comment #4
pplantinga CreditAttribution: pplantinga commentedI'm guessing a separate issue should be filed for converting the calls to theme() to drupal_render()?
Here's a possible patch.
A quick question though, the css will be converted and '#title' be removed with #1842140: Remove title and wrapper div from item-list.html.twig, right?
Comment #6
pplantinga CreditAttribution: pplantinga commentedOkay... let's give this another shot.
Comment #8
pplantinga CreditAttribution: pplantinga commented#6: theme-item-list-to-links-2032645-6.patch queued for re-testing.
Comment #10
pplantinga CreditAttribution: pplantinga commentedApparently we are now escaping a string that we weren't before, and that was throwing off a test.
Here's the version with the test updated.
Comment #11
pplantinga CreditAttribution: pplantinga commentedComment #11.0
pplantinga CreditAttribution: pplantinga commentedremove pager
Comment #12
steveoliver CreditAttribution: steveoliver commentedclass as a top level argument, rather than being #attributes, was the only thing that jumped out of me when reviewing this diff.
As a follow-up to this issue, since there already is a @todo in core for it(theme_links(), theme.inc:1706), #header['class'] should be replaced with #header['attributes']['class'].
Re: #4, I do believe the title, wrapper, CSS are supposed to happen in the other issue(s).
jenlampton: I'm not totally understanding the proposed resolution, but it seems the scope of this issue is fully addressed by this latest patch in #10.
If so, +1 to RTBC.
Comment #12.0
steveoliver CreditAttribution: steveoliver commentedup
Comment #12.1
jenlamptonup
Comment #12.2
jenlamptonupdated
Comment #13
jenlampton@steveoliver the basic idea is to replace theme_item_list, which currently outputs an unnecesary div and title, with just an item list.
There were instances in core where we need the ability to have a div and a title added around an item list, so I went through core and identified all the places where that happens. Most of the time it's actually when we're generating a list of links, and as it turns out, we have a theme function for that: theme_links.
The scope of *this* issue is to identify all the calls to theme_item_list where we should be calling theme_links instead, and change them.
Once this is done, we can then work on #1842140: Remove title and wrapper div from item-list.html.twig without breaking tests.
Comment #13.0
jenlamptonupdate
Comment #13.1
jenlamptonremove unneccary rows
Comment #14
jenlamptonRerolled.
I updated the summary to indicate which things should happen in this issue, and which in the other. Hopefully that will help clarify.
I'm going to leave the item_list test with a title in here, and we can remove that in #1842140: Remove title and wrapper div from item-list.html.twig
I also don't know if the word 'module' is ever translated, but just in case I wrapped the heading for update.php in a new t().
Comment #14.0
jenlamptonlist
Comment #15
areke CreditAttribution: areke commentedIt looks like after 6 months of sitting here, the code needs to be re-rolled.
Comment #16
forbesgraham CreditAttribution: forbesgraham commentedComment #17
forbesgraham CreditAttribution: forbesgraham commentedRe-rolling patch from comment 14.
Comment #18
forbesgraham CreditAttribution: forbesgraham commentedComment #19
pplantinga CreditAttribution: pplantinga commentedLooks good to me.
Comment #20
chx CreditAttribution: chx commentedComment #21
webchickThis all looks like a great clean-up! One quick thing...
That's a bit weird and afaik should not be necessary? Or at least I can't figure out why it would've passed before and not now.
Comment #22
pplantinga CreditAttribution: pplantinga commentedSince this is part of a title that used to be just spit out as plain HTML, it wasn't checked to see if it was html-ready.
Old output:
Today's
New output:
Today's
I think the new output is better HTML, but correct me if I'm wrong...
Comment #23
jhedstromComment #24
adci_contributor CreditAttribution: adci_contributor commentedTrying to reroll
Comment #25
adci_contributor CreditAttribution: adci_contributor commentedComment #27
gbisht CreditAttribution: gbisht commentedPatch rerolled!
Comment #29
ankitgarg CreditAttribution: ankitgarg commentedrerolled.
Comment #30
ravi.khetri CreditAttribution: ravi.khetri commentedRerolled.
Comment #32
SumeetJaggi CreditAttribution: SumeetJaggi commentedRe Rolled!
Comment #34
Manuel Garcia CreditAttribution: Manuel Garcia commentedPatch applies cleanly.
Comment #35
Manuel Garcia CreditAttribution: Manuel Garcia commentedDrupal\statistics\Tests\StatisticsReportsTest was failing due to fatal error, since the previous patch was calling check_plain, which is now String::checkPlain().
Plenty of tests to fix stil though.
Comment #37
cutesquirrel CreditAttribution: cutesquirrel commentedComment #38
cutesquirrel CreditAttribution: cutesquirrel commentedHere is the fixed #35 patch : the theme_links waited for an "url" key and not a "href" key.
I've also fixed the title which display the comment count on each popular node link.
Comment #39
rteijeiro CreditAttribution: rteijeiro commentedFixed just a couple of nitpicks. It's RTBC for me.
Toolbar BEFORE
Toolbar AFTER
Comment #42
akalata CreditAttribution: akalata commentedComment #43
akalata CreditAttribution: akalata commentedComment #44
marieke_h CreditAttribution: marieke_h at XIO commentedI am at DrupalCon Barcelona mentored sprint. And will try to do this reroll (together with jnnck).
Documentation for reroll https://www.drupal.org/patch/reroll
Comment #45
marieke_h CreditAttribution: marieke_h at XIO commentedWe rerolled the patch from #39.
Let's see what the testbot says.
Comment #46
marieke_h CreditAttribution: marieke_h at XIO commentedComment #48
marieke_h CreditAttribution: marieke_h at XIO commentedComment #49
CyberschorschI am reviewing this issue at dc barcelona
Comment #52
CyberschorschComment #54
CyberschorschI removed a still existing
'#title' => NULL
and removed the changes in the StatisticReportsTest which breaks the current tests.As webchick mentioned in #21, I don't think we have to checkplain there.
If we look in the list in the issue summary, I am not sure what todo about the #prefix elements...
Comment #55
CyberschorschComment #56
CyberschorschThis is the correct interdiff
Comment #57
akalata CreditAttribution: akalata commentedShouldn't this be changed to
'#theme' => 'links'
?These changes were introduced in #38, but I'm not sure they're in scope of this issue?
core/includes/theme.maintenance.inc
described in the issue summary has not been included in this patch.core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
may no longer be necessary, but we may need to investigate where that was changed and update the issue summary accordingly.core/modules/views/views.theme.inc
may no longer be necessary, but we may need to investigate where that was changed and update the issue summary accordingly.core/update.php
no longer exists in HEAD, but we may need to investigate where that was changed and update the issue summary accordingly.Comment #58
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedHandled the comments above. 8.0.x HEAD has a few other instances for theme_item_list with #title as well.
Uploading the updated patch here.
Comment #61
piyuesh23 CreditAttribution: piyuesh23 at QED42 commentedPatch created with core folder as the base. Uploading the correct patch again.
Comment #64
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer commentedIt's great to see progress on this =)
Let's do these in short array syntax.
Comment #67
joelpittetDid the array() that I could, removed the return that was left in there and this should be good for a review.
Comment #69
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedBit of a non-issue, but we could avoid using if else here by returning FALSE early if !$has_rows... makes for easier reading
Other than this, interdiff and patch looks good to me. Good catch @joelpittet on removing that leftover return btw.
Next step, fix the failing tests :)
Comment #70
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commentedAddressing #69
Comment #72
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commented