Problem/Motivation
We want to get rid of theme_system_compact_link() one way or another.
Proposed resolution
Convert it to a render element #type. A Twig template is overkill. The output can be tested by navigating to /admin/config, /admin/index, /admin/people/permissions.
The markup changes slightly at /admin/people/permissions. Because the element is inside a form the link wrapper has a form-wrapper class added. This doesn't affect the functionality or appearance.
Remaining tasks
None
User interface changes
n/a
API changes
theme_system_compact_link() removed.
Before:
$variables['system_compact_link'] = array(
'#theme' => 'system_compact_link',
);
After:
$variables['system_compact_link'] = array(
'#type' => 'system_compact_link',
);
Original report by @jenlampton
Original code:
function theme_system_compact_link() {
$output = '<div class="compact-link">';
if (system_admin_compact_mode()) {
$output .= l(t('Show descriptions'), 'admin/compact/off', array('attributes' => array('title' => t('Expand layout to include descriptions.')), 'query' => drupal_get_destination()));
}
else {
$output .= l(t('Hide descriptions'), 'admin/compact/on', array('attributes' => array('title' => t('Compress layout by hiding descriptions.')), 'query' => drupal_get_destination()));
}
$output .= '</div>';
return $output;
}
Render array that will achieve the same thing:
$system_compact_link = array(
'#type' => 'link',
'#href' => 'admin/compact/off',
'#title' => t('Show descriptions'),
'#attributes' => array(
'title' => t('Expand layout to include descriptions.'),
),
'#options' => array('query' => drupal_get_destination()),
'#theme_wrappers' => array('container'),
'#wrapper_container_attributes' => array(
'class' => array('compact-link'),
),
);
if (!system_admin_compact_mode()) {
$system_compact_link['#href'] = 'admin/compact/on';
$system_compact_link['#title'] = t('Hide descriptions');
$system_compact_link['#attributes']['title'] = t('Compress layout by hiding descriptions.');
}
$output .= drupal_render($system_compact_link);
Beta phase evaluation
Issue category | Task because parent item #1757550: [Meta] Convert core theme functions to Twig templates is a task |
---|---|
Issue priority | Major because parent item #1757550: [Meta] Convert core theme functions to Twig templates is Major. |
Prioritized changes | The main goal of this issue is to follow up on #1987410: [meta] system.module - Convert theme_ functions to Twig. These issues were recently moved to Major, but since this issue was already closed it likely was not updated. |
Disruption | This change should not be considered disruptive because markup and functionality are not changing, just the method used to generate the markup. |
Comment | File | Size | Author |
---|---|---|---|
#151 | Screen Shot 2014-11-25 at 3.56.54 PM.png | 20.5 KB | lauriii |
#151 | Screen Shot 2014-11-25 at 3.56.32 PM.png | 56.05 KB | lauriii |
#151 | Screen Shot 2014-11-25 at 3.56.22 PM.png | 47.11 KB | lauriii |
#151 | Screen Shot 2014-11-25 at 3.56.03 PM.png | 35.87 KB | lauriii |
#151 | Screen Shot 2014-11-25 at 3.55.52 PM.png | 57.09 KB | lauriii |
Comments
Comment #1
jenlamptonwhoopsie, wrong theme func name
Comment #1.0
jenlamptonwring name fix
Comment #2
thedavidmeister CreditAttribution: thedavidmeister commentedupdating the title.
This is part of #1595614: [meta] Remove all the theme functions and templates in core that simply output a link. Replace with #type 'link' render arrays
Comment #2.0
thedavidmeister CreditAttribution: thedavidmeister commentedadd twig example
Comment #2.1
jenlamptoncode
Comment #2.2
jenlamptonmore code
Comment #2.3
jenlamptoncode
Comment #2.4
jenlamptoncorrect code
Comment #2.5
jenlamptonmore code
Comment #3
jenlamptonhere we go
Comment #4
ericrdb CreditAttribution: ericrdb commentedTo test:
From the admin/index page, click on "Show Descriptions" and verify that the text displays. After page reloads, click "Hide Descriptions" and verify that the descriptor text is removed.
Also, on admin/people/permissions, perform above show/hide description action and verify text shows and hides accordingly.
Both tests worked.
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedThe patch looks good. I do feel like the three instances of this link could be provided by a central system_build_compact_link() function, but I'm sure that could be a followup issue as it's not required in order to remove theme_system_compact_link().
Comment #6
star-szrMinor touch-up needed:
Two spaces between => and drupal_render(), remove one.
Comment #7
ericrdb CreditAttribution: ericrdb commentedOK, spaces removed. First time uploading a patch, I'm guessing the file needed to be renamed.
Will this need further review?
Comment #9
star-szr@ericrdb - thanks! The patch from #3 no longer applies and will first need a reroll.
Also, you should not edit patch files directly. Instead, apply the patch locally and create a new patch :)
Comment #10
ericrdb CreditAttribution: ericrdb commentedThis proved helpful guide for naming patches: https://drupal.org/patch/submit
Trying again.
Comment #11
ericrdb CreditAttribution: ericrdb commentedComment #13
star-szr#10: core-remove_theme_system_compact_link-1833932-9.patch queued for re-testing.
Comment #14
star-szrNice work @ericrdb! I just hit re-test, it looks like we had a random test failure.
Comment #15
jenlamptonrerolled :)
Comment #16
ericrdb CreditAttribution: ericrdb commentedCool - thanks for the patch links too @Cottser.
Comment #17
star-szrPatch in #10 has one more fixed up drupal_render() line :)
Comment #18
thedavidmeister CreditAttribution: thedavidmeister commented+ '#children' => drupal_render($system_compact_link),
double space before drupal_render
+ $output = drupal_render($system_compact);
double space before =
Comment #19
Eric_A CreditAttribution: Eric_A commentedWe should not render the container child immediately, but lazy-render by using a child element like 'system_compact_link' instead of the "#children" property. See remarks by @Fabianx and @catch in #2031301: Replace theme_more_link() and replace with #type 'more_link'.
Since theme_container() doesn't render child elements we then need to build our container render array with '#theme_wrappers' instead of '#theme'.
Comment #20
Eric_A CreditAttribution: Eric_A commentedAddresses #18 and #19.
Comment #21
jenlamptonit also might be worth fixing theme_container so that it can render it's contents, but that's a follow-up issue.
If we're going to use a theme_wrapper, then we certainly don't need two arrays.
How about something like this:
Also, this patch should depend on #2042285: #theme_wrappers should be able to have a unique set of variables per wrapper hook
Comment #21.0
jenlamptonbetter code
Comment #21.1
jenlamptonexample code update
Comment #22
areke CreditAttribution: areke commentedThis patch needs to be re-rolled; it doesn't apply anymore. The things jenlampton mentioned should also be fixed.
Comment #23
mikemiles86rerolling patch.
Comment #24
mikemiles86Rerolled the patch so that it works again, as well as, added the refactoring suggested by jenlampton.
Comment #25
star-szrThanks @mikemiles86!
Comment #26
parthipanramesh CreditAttribution: parthipanramesh commentedPatch works fine. Thank you!
Comment #27
webchickNice clean-up. How come there are no hunks to remove the old theme function though?
Comment #28
lokapujyaSome changes were removed in the last patch from the patch in #20 with no explanation. What about the changes in system.module (that remove the old function), system.admin.inc, and user.admin.inc?
The changes in user.admin.inc, if they are still part of this patch, will need to be rerolled due to #1938888: Convert user_admin_permissions to a new-style Form object.
Comment #29
star-szrNeeds work based on the above.
Comment #30
lokapujyaHere is a re-roll of #20. I'll follow up by integrating the changes from #24.
Comment #31
lokapujyaThe patch in #30 was messed up. This one is #20 re-rolled, plus the changes from #24.
Comment #32
lokapujyaComment #33
lokapujyaRenaming the last patch.
Comment #35
mikemiles86lokapujya, thanks for re-rolling. sorry everyone for my messed up re-roll, it was my first time attempting one.
Comment #36
lokapujya33: 1833932-33.patch queued for re-testing.
Comment #38
lokapujyareroll.
Comment #39
lokapujyaLook into using #route_name instead of #href.
Comment #40
longwave#2151107: Convert theme_system_compact_link() to Twig has been going on in parallel, I am not sure which is the best approach here. #38 adds quite a lot of code duplication to be able to remove the theme function, and it looks like whatever we do will conflict and need refactoring when #2151095: Convert theme_admin_page() to Twig and #2151105: Convert theme_system_admin_index() to Twig get in.
Comment #41
joelpittetSorry I'm late to the party here but could we go with something like:
#type 'system_compact_link'?
And if it's feasible to remove the wrapper div and just use CSS like this: #2031301: Replace theme_more_link() and replace with #type 'more_link'
Comment #42
lokapujyaI agree that we should remove the duplication. Unassigned because I don't understand how it should integrate with twig yet.
Comment #43
star-szrCan we do "suggestions" with #type? Like #type = link__system_compact ?
Comment #44
joelpittetI don't think so but it would be worth a stab...
Comment #45
joelpittetGoing to try this using the same approach as #2031301: Replace theme_more_link() and replace with #type 'more_link'
Comment #46
joelpittetThis seems to work well. Needs a markup comparison.
No need for profiling, it only ever shows up once on a page per admin.
Couldn't use $this->t() because it is a static preRender call, maybe there is a better way to deal with that?
Anyways... enjoy.
Comment #47
joelpittetComment #51
joelpittetHuh, I should have known better I introduced a bug in MoreLink unintentionally, I've included the fix in this patch as well.
'class' needs to be an array.
Comment #52
star-szrLooking really good overall. I manually tested at /admin/config (added to issue summary).
Minor: link has an extra space in there.
The first line needs to end in a colon so that the following lines become a list. Ref. https://www.drupal.org/node/1354#lists
Can we use $this->t()?
Comment #53
star-szrNevermind 3 I guess, didn't see that it was a static method.
Comment #54
star-szrYou know what, if those are the only changes then here's a patch :) RTBC from me.
Comment #55
star-szrComment #56
star-szrActually, this was missing the title attribute after doing a proper markup comparison/diff. Here's the before and after with the attached patch:
Before:
After (including twig_debug):
Comment #57
thedavidmeister CreditAttribution: thedavidmeister commentedAny chance of introducing tests for the expected markup while we're here?
Comment #58
lauriiiAdded some tests there.
Comment #59
lauriii:<
Comment #63
lauriiiRerolled
Comment #64
lauriiiOk I'm gonna fix this mess
Comment #65
lauriiiHopefully I fixed my own mess. Forget last 2 patches
Comment #67
joelpittetFixing, thanks for the test!
Comment #68
joelpittetThe system compact link was missing from patch #65
Comment #69
lokapujyaAt admin/people/permissions, the wrapper and the system compact link elements have the same ID (unlike D7). Is this the way form API is supposed to work or do we need a new issue? Otherwise, this is RTBC for me.
Comment #70
joelpittetOh dang it seems container = form-wrapper for some confusing reason and it does lots of things it shouldn't...
I'm a bit unsure how to proceed here, maybe just #prefix/#suffix hard coded... argh. Thoughts?
Comment #71
lokapujyasystem_compact_link isn't a form type. Back in #38, we used #markup and set it with drupal_render(). Not sure why it changed?
Comment #72
lauriiiComment #73
joelpittet@lokapujya It's not intended to be a form type, it's just a Render Element type element like Link, MoreLink, Table.
It doesn't extend FormElement, but unfortunately the theme_wrapper does extend form wrapper and it's super weird/unintuitive that theme_wrapper => 'container' acts like a form element with it's processContainer and preRenderGroup...
@laurii thanks for that patch though that is a bit confusing why that would work... don't you think so?
Comment #74
lokapujyaI think we may need to go the route in #72, but I opened an issue for investigating an alternative. If you continue from #68 and apply this patch #2347209: Render regular element in a form should not duplicate container ID., the IDs are removed.
Comment #75
lokapujyaThe array can just go directly inside drupal_render().
First, let's figure out if we want drupal_render() or Form API. EDIT: A third option may be #prefix.
Comment #76
star-szrI'm fairly sure that generates an error, see https://www.drupal.org/node/2006152#reviewer-notes :)
Comment #77
cilefen CreditAttribution: cilefen commentedRerolled #72.
Comment #78
cilefen CreditAttribution: cilefen commentedI am trying to understand this issue but I don't understand why we would want to drupal_render() early.
Comment #79
joelpittet@cilefen we don't that was to prove a point I assume. #type inside a form element seem to get a bunch of extra cruft on the container and the element as well.
View source on admin/people/permissions to see the extra ids and stuff on the markup.
Comment #80
tim.plunkettPlease use #route_name and #route_parameters, we're trying to kill #href.
Look, they used to be routes! Should be easy.
Comment #81
lauriiiFixed #80. #73 has to be still fixed.
Comment #83
lauriiiComment #87
tim.plunkettThat's not a reasonable change to the expectations. Please revert.
Comment #88
lauriiiRemoved .swp from the patch
Comment #89
tim.plunkettSorry, I misunderstood the change, I didn't realize this was a brand new test.
Comment #90
joelpittetNeed to check this out again to see if the ID's that got tagged on to the container are still there or not. It's so weird that types act different depending on whether they are used in a form or not... I hope that goes away.
Comment #91
Xen CreditAttribution: Xen commentedTested 1833932-87.patch on admin/config and permissions page as described in #4.
Unit tests pass.
The container of the link has the compact-link class.
Comment #92
lauriii@xen thanks for a review!
Everything else looks good for me but I found out there's still duplicate ID's on permissions form
Comment #93
lauriiiI removed the ID completely since there's no ID in any other use cases than permission form. This also fixes the issue mentioned on #90 and #92.
Comment #94
star-szrManually tested at these three paths, the only difference is that the link on /admin/people/permissions has an extra class of "form-wrapper" added.
This description should be updated, it's the same as the Link render element.
Other than that this is looking good!
Comment #95
lokapujyaUpdated the comment and the one for More Link.
Comment #97
star-szrCool, testbot is having some issues but will try our luck at RTBC and see how long that sticks. Thanks @lokapujya!
Comment #99
alexpottl() no longer exists.
$this->t() not t()
Also we need a change record to explain that the theme function is going away and how to replace it.
Comment #100
joelpittet@alexpott, for the t() how do we use $this->t() inside a static or is there another way to do the processing?
Comment #101
subhojit777Comment #102
subhojit777Comment #103
subhojit777@joelpittet may be this can help http://stackoverflow.com/a/2286720/1233922
Comment #104
lauriiiComment #108
cilefen CreditAttribution: cilefen commentedI can't reproduce the install error from #104 and I am not sure why Url is considered a double-use. This is an experiment using the url static.
Comment #110
lauriiiLets try this out..
Comment #111
subhojit777Comment #112
mikispeed CreditAttribution: mikispeed commentedMore Link changes - does this belongs here? Introduced in #59.
#router_parameters should be in new line for better readability...
.. and not sure about #href, like stated above this should #href should be killed.
Note from #99 still not implemented. l() no longer exists.
Everything else seems fine and patch applies cleanly against current HEAD. Tested on pages:
Comment #113
lauriiiComment #114
balagan CreditAttribution: balagan commentedComment #115
lauriiiI guess the more link changes doesnt belong to this issue. Dunno where they're from.
Comment #116
lauriiiUps found the actual comment #51. Maybe we can include the bug fix there.
Comment #117
balagan CreditAttribution: balagan commented#href is not used, we should delete it from here, and I do not see #route_name and #route_parameters used.
Yes, there is one occurence of the l() function in documentation, that should be changed to Drupal::l()
Alltogether, it looks fine. It seems we do not even need the #route_name and #route_parameters, we do not use the #href.
The documentation part should be updated by someone who understands what is going on.
Comment #118
balagan CreditAttribution: balagan commentedComment #119
joelpittet@mikispeed
Re: #112.1 Technically it should be a quick fix follow-up. Would you mind creating that new issue, I can move the patch over to it if you'd prefer or you can tackle that too?
Comment #120
mikispeed CreditAttribution: mikispeed commented@joelpittet I will now create new issue and post a patch there.
Comment #121
mikispeed CreditAttribution: mikispeed commentedCreated new issue from #112.1 and posted a patch in #2368957: Set class on MoreLink as array instead as string.
Comment #122
joelpittet@mikispeed thanks we can take it out of this patch now. I've RTBCd that morelink followup.
Comment #123
mikispeed CreditAttribution: mikispeed commentedOk, so first a reroll (I see it needed per #111) and MoreLink part taken out.
Comment #124
lauriiiLets see what test bot says :)
Comment #125
akalata CreditAttribution: akalata commentedAnother quick style review:
An extra empty line got added in #104 - not sure why?
Comments should wrap at 80 characters
Short arrays should use the compact array style (
array('mode' => 'off')
becomes['mode' => 'off']
).Comment #126
akalata CreditAttribution: akalata commentedComment #127
lauriiiThanks a lot @akalata for your review! I fixed points 1. and 2. on the patch and they were good catch but I'm not very sure about 3. point because there's no policy for which style we should use and in the other parts of the file we are using the array() syntax. I personally prefer shorter syntax but because there's no clear policy which one to use I would leave it as is. Are you ok with this or should we change the whole file to follow that style?
Comment #128
akalata CreditAttribution: akalata commented@lauriii, I'm fine with that, I've just been following @joelpittet's lead on short array style for small arrays that we can put all on one line. No "official" reason to change, I don't think.
Comment #129
akalata CreditAttribution: akalata commentedManually reviewed the latest patch for code style and out-of-scope changes. Everything looks okay to me.
According to @Cottser, no change record for theme_ function removal is necessary - which makes sense in this case since this is only used on the admin side.
Comment #130
lauriiiComment #131
alexpottThis issue is a normal task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
Comment #132
akalata CreditAttribution: akalata commentedComment #133
akalata CreditAttribution: akalata commentedComment #134
akalata CreditAttribution: akalata commentedComment #135
alexpottThis should be using the plugin's t() method - ie.
$this->t()
We should inject the link_generator instead of using
\Drupal::l()
. But I think we should open a followup to do this since we should inject this into the parent class (Link) since that needs it too.Comment #136
iMiksuComment #137
iMiksuThe method is static, therefore using
static::t()
instead.Comment #138
iMiksuWhoops, sorry. Some unexpected files came in to the patch. Rerolling.
Comment #139
iMiksuThere you go. Previous interdiff still applies.
Comment #142
lauriiiTo use static::t we need to have static t method in the class.
Comment #143
lauriiiAfter a short discussion on IRC with GaborHojtsy and alexpott we decided to use just simply
t()
instead of\Drupal::translation()->translate
orstatic::t()
there.Comment #144
alexpottSo that means the patch in #127 looks good. Sorry for derailing the issue. Perhaps someone can re-upload that to see if it still passes testbot and to make it the latest patch.
Comment #145
lanchez CreditAttribution: lanchez commentedI'll test that out.
Comment #146
lanchez CreditAttribution: lanchez commentedI tested the patch and that applied fine. The patch is the exact same as in 127 but just renamed.
Comment #147
lanchez CreditAttribution: lanchez commentedActually, the darned patch did it wrong....so i'll make another one.
Comment #148
lanchez CreditAttribution: lanchez commentedSo once more with t() functions :)
Comment #149
lauriiiReviewed against #113. It seems to work and fixes the issue described.
Comment #150
alexpottWe need screenshots and html comparisons to prove this issue has not broken anything - with compact mode enabled and disabled.
Comment #151
lauriiiHere's also markup from the permissions page. No ID's as you can see:
Comment #152
alexpottCommitted 9e163fc and pushed to 8.0.x. Thanks!
Thanks making the screenshots and for adding the beta evaluation for to the issue summary.