Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Jun 2015 at 19:04 UTC
Updated:
4 Sep 2015 at 12:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
cilefen commentedComment #2
cilefen commentedI am working on this.
Comment #3
cilefen commentedThank you to @pwolanin for describing the technique.
Comment #4
pwolanin commentedLet's use array() so the code inside the method uses the same style.
Comment #5
cilefen commentedNote #2501975: Determine how to update code that currently joins strings in SafeMarkup::set().
Comment #6
colbol commentedComment #7
pwolanin commentedComment #8
pwolanin commentedI think this is a good example of converting string concatenation into a render array.
It would be good to add to the ViewListBuilderTest unit test to check that paths and titles are properly escaped and not double escaped.
Comment #9
cilefen commentedComment #10
cilefen commentedWe do not need this use. I had tested against a call to SafeMarkup::escape() but I feel it is better to not rely on the same function for both the escaping and the assert.
Comment #11
cilefen commentedComment #12
yesct commentedI'm going to review this.
Can we fake the test out somehow and trigger it to make sure it works? Maybe by ... turning auto escape off?
Comment #13
yesct commentedso reading the patch, the changes make sense, but I was unable to get the test to fail.
first I tried getting the test to fail with *most* of the fix by taking out the SafeMarkup::escape()... but it passes.
This might indicate (as @cilefen said in irc)
1) render array #markup is intrinsically safe because of some other thing 2) something else in this system fixes it
then I tried the test out on head, hoping first that it would pass, and then I could make a change to get it to fail, but it is failing... cause of some other reason. I attached the changes I did trying to get the test to work on head.
None of these "patches" should be committed, just attaching them so people can see exactly what I did.
Comment #15
pwolanin commented@YesCT - here's a change on top of the patch that makes the test fail
Comment #18
pwolanin commentedoops, silly me - fat finger in the editor.
Comment #20
pwolanin commentedReposting Chris' patch from #11, since that's what we actually want considered for commit.
Comment #21
yesct commentedI looked at that patch again. Approach makes sense to me, and we showed that the test is a good test.
I didn't test this manually. If we want to, we should figure out steps to reproduce to get to a page that uses this output.
Comment #22
xjmYes please. :)
Comment #23
pwolanin commentedThe output affected by this patch is the views UI views listing at /admin/structure/views
With the patch the output looks correct (see 1st screenshot) - paths without % are linked, while those with are plain text.
I added in some extra text to each #prefix in the render array to confirm this code affects that page.
I also cloned a default View edited the path to have & in it. It shows up correctly in the UI and checking the HTML source verifies that it's correctly singly-escaped.
UI

HTML

Comment #24
xjmCan we have test coverage and/or manual testing for a case with multiple page displays and paths? The unit test only seems to cover a single entry.
Comment #25
cilefen commented@xjm I realize the wisdom in this. It's a list builder.
Comment #26
pwolanin commented@xjm - the overview page I tested manually did have some with multiple paths. I don't know that more manual testing is needed.
Comment #27
xjmOkay, just automated tests then. :)
Comment #28
dawehnerI thought to just do that, but then well, what the unit test is doing is this line of code:
which then returns $data, which has multiple page displays and so paths, which we test. I think the justifies the RTBC
Comment #29
xjmHmmm. I really think it should have an integration test.
Comment #30
cilefen commentedThe tests.
Comment #32
cilefen commentedWhoops - I had some other test methods commented-out when I tested locally and there was an ordering problem.
Comment #33
cilefen commentedWhoops - I had some other test methods commented-out when I tested locally and there was an ordering problem.
Comment #34
dawehnerThat is actually a 100% fair point. Safemarkup fixes should have integration tests ... unit tests are for logic checking, escaping happens on the application level.
Comment #36
cilefen commented#32 works for me locally. Advice is welcome.
Comment #37
cilefen commentedRe #36, the reason is simple - the expected output contains a site subpath.
Comment #38
cilefen commentedComment #39
davidhernandezCan we get with and without test patches?
Comment #40
cilefen commentedComment #42
joelpittetThank you @cilefen! Back to RTBC.
Comment #43
alexpottThe output of getDisplayPaths is already escaped so this is not actually doing anything afaics. The mindset of all SafeMarkup patches needs to first ask the question is this really necessary - is it already escaped - or can we leave the render system to filter or escape it later.
PHPUnit assertions should always be the expected value first plus the message should be what you are testing not an error message.
Comment #44
joelpittet@alexpott nice! I'd rather not have to do that ugly looking pattern to comma separate some strings.
Comment #45
dawehner+1
Comment #46
alexpottAfter discussing with @xjm, realised that actually if if the
<script>containing path has a % then it would be admin filtered away and wrong. We need to investigate using a twig template to comma join the safe strings that displayPaths is generating.Comment #47
joelpittetProbably need a renderer and not sure if mocking that is possible... but I did the same test that was done before.
Comment #48
xjmThanks @joelpittet.
I think this still needs testing and test coverage for the
%case, as well as combinations of that and the linked path case.The safe_join/inline template is an improvement. I do think the comma-separated item list template would be more semantic and help us in a bunch of places.
Comment #49
joelpittetI'm a bit gun-shy on unit test still but here's an attempt to add to what @alexpott wrote. Hopefully this will do the job?
I did with and without text after the placeholder in a local test, both show the same result so I expect this will do the job.
Comment #50
alexpottCan we add another test so we test escaping the path where a link in not generated by ie. when it includes a placeholder like
%1. SeeViewListBuilder::getDisplayPaths().Let's use ->assertEscaped() as this is escaped and not filtered text.
Let's put some html in here.
Comment #51
alexpott[Edit:deleted comment on wrong issue - thanks @cilefen!]
Comment #52
cilefen commented@alexpott is #51 on the correct issue?
Comment #53
larowlanworking on this
Comment #54
larowlanaddresses #50
Comment #55
joelpittetRe-RTBC from #44 with added test coverage for script tags with % as requested by #46 #48 and #50
Comment #56
joelpittetAlso thanks @larowlan for figuring that out.
Comment #57
alexpottI thought we agreed to add a real template for this since lots of places need this. Or maybe rather than a template we could add a static function to InlineTemplate to return a template to do this?
Comment #58
joelpittet@alexpott yes, you are correct. Here is more-or-less what we discussed. Though my SUGGESTION-foo is lacking in the theme layer. I can't get the system suggestion to pickup! the seven one picks up like a charm so this should look fine for testing... Need help from @Cottser or @lauriii may know this trickery.
Comment #60
joelpittetNote to the next patch/patcher:
['#context']['display_paths'] just needs to be ['#items'] now for that test to pass.
Comment #61
lauriiiIs there a specific reason why loop.last cannot be used? It would make this a bit more easier to understand when someone is over viewing the template
Comment #62
joelpittet@lauriii, nope just change the order, doesn't matter to me.
Main problem is we need to figure out why the system template won't pickup the suggestion.
Comment #63
akalata commentedComment #64
akalata commentedMaybe it was picking up the suggestion, and the test hadn't been updated for the new template?
Comment #65
akalata commentedFrom system_theme():
So, let's do the same here! ... Though I'm still trying to figure out how.
Comment #66
davidhernandezThe suggestion should be
item_list__inline.__is the default delimiter. If you want--you have specify it with the third parameter.Comment #67
davidhernandezOh wait, ignore that. I see, that was dumb. Hmm. It isn't picking up the file at all? How can this be tested?
Comment #68
akalata commentedEasiest manual testing location I've found is in the Views UI, the views list page (admin/structure/views) where it lists multiple paths (Path column).
joelpittet found that he had to add
core/themes/seven/templates/item-list--inline.html.twigfor Seven in order to test this manually.The attached path removes this additional template file (since things ideally should work without it), and adds the item_list__inline declaration to drupal_common_theme(). It also makes laurii's preferred tweak from #61.
The screenshots are as follows, all showing the Path column for the core Files view:
I got stuck on trying to get phpstorm and xdebug talking to each other to figure out what was going on with the values coming from ViewListBuilder.
Comment #70
akalata commentedComment #71
alexpottI think we need an explicit test for this template.
are we sure we want to support titling in an "inline" item list?
Comment #72
akalata commentedI think removing the title does make sense.
I couldn't find anyplace where a template itself is tested -- @alexpott did you mean test the template suggestions? I see a few examples of that in core.
Comment #73
joelpittet@alexpott re #71if we extend from item list we should keep the title I think, if we go to a new template likely not needed to have a title, but they should be as close as possible to eachother or they really don't need to share the same namespace.
@akalata We shouldn't have to make that change but thanks for showing that. I have a feeling the preprocess is not working for the suggestions, that may be completely another issue that we still have hanging around.(@lauriii or @Cottser may no about this) if it is indeed the case. Here is the issue #939462: Specific preprocess functions for theme hook suggestions are not invoked
Comment #74
akalata commentedAre we trying to shoehorn ourselves into the item_list template too much? I think we might be.
as well as
Comment #75
akalata commentedPosting progress on implementation switch before working on tests.
Comment #77
akalata commentedLet's try this. Ignoring #75.
Comment #78
akalata commentedUpdating per @joelpittet's review in-person at MWDS:
Comment #79
joelpittetSo excited about the use-case for my favourite front-end syntax-sugar in twig the for...else loop!
Minor nit to remove the double line-break at end of file on next roll. Thanks for the fixes and trying that out @akalata!
Comment #80
dawehnerI don't actually get this sub items render array, so I was wondering whether it would be a good idea to give some examples with @code @endcode
MH, just wondering: doesn't the type ul vs. ol depends on the kind of data you list, so should this be the responsibility of the caller? It feels like ordered vs. unordered list is semantically different. I was starting to think about that because I wondered why ul should be preferred over ol. So what about something like $variables['#list_type'] or so
We seem to not have a classy overrides with the attributes involved?
I really like this kind of API
Comment #81
akalata commented80.1 - I'm not sure, that was part of the item-list template that I copied.
80.2 - This is actually from an earlier patch and is no longer needed.
80.3 - Oooh, good catch! Though now I'm very tempted to remove the "wrapper" attribute entirely, since it makes the Classy template less streamlined.
Comment #82
akalata commentedAfter more discussion with Joel, we agreed to remove both types of attributes, which means that we do not need to add the preprocess function or Classy template.
I will work on a test now.
Comment #83
akalata commentedBut we still need a preprocess function to sanitize the separator value...
Comment #84
joelpittetCan remove one new line before and after this function.
Could you add separator to the list of items contained in the $variables?
Because we escape all variables in the template this ensures we prevent Xss attacks but also allows certain tags through. May need to re-work that to include why we are marking values as safe.
Moar bunnies are needed here.
Comment #85
akalata commentedRe 84.2, I also added $variables['empty'] for completeness' sake.
Comment #86
joelpittetThanks for adding both:)
That context variable is throwing me a bit. Anybody know where this came from or what it's for?
2 spaces back.
We have some fun rules for these variables:) We don't actually say the 'type' of data. For array, we say 'list'.
https://www.drupal.org/node/1823416#datatypes
Comment #87
akalata commentedThanks for the continued reviews!
86.2 - No clue. :) Just following what was already established in core.
Comment #88
akalata commentedFixing a typo and removing the context variable (which was added for a specific use case and not globally, per @joelpittet's sleuthing).
Comment #89
joelpittetPeriods at end of the lines are the last nits I could find, they could be fixed on commit:)
I think this is good to go, has ample tests from multiple angles (the safemarkup and the new theme template).
Comment #91
dawehnerGreat improvements since my last review!! Great work, thank you!
Comment #92
alexpottMaybe we should only permit a list of specific tags rather than the entire admin list. This is because the admin list includes elements that are block level elements like
panddiv. These elements don't make much sense here. In fact is there any element other thanbrthat makes sense?Comment #93
cilefen commentedComment #94
joelpittetI like that idea @dawehner & @cilefen. Anybody that needs more can write a preprocess and add whatever they want.
Comment #95
yesct commentedthis is asserting the item is displayed.
this is not asserting that the empty text is not displayed.
Hm. I guess it might be. Looking up assertThemeOutput() seems to be asserting all the themed output is equal to expected. (Not what I assumed which was that it was asserting the themed output contained the expected string.)
so this is fine.
Comment #96
star-szrLooks like a nice solution, thanks all.
Comment #97
alexpottSo just a word on performance... this orders of magnitude slower than implode. Doing a small array of 20 items 10 times with renderer primed.
If you prime the render with the template you get...
So the good thing is that only the first is costly - loading PHP code etc... but basically doing this seems to add 20ms on any page that uses it. Th.at that maybe on a webserver with opcaching enabled the startup cost will be smaller.
Comment #100
dawehnerTripple post! Nice
Well yeah, for sure this is no suprise here at ALL.
Comment #101
wim leersI think 20 ms for something so simple is pretty much unacceptable? Why would Twig be this slow for something so simple? Is it a case that isn't optimized well in Twig, because of the inline template?
Tentatively blocking on @Fabianx' feedback.
Comment #102
alexpottSo as I suspected with opcache this gets a bit better.
Still 4ms - maybe this should be a theme function and not twig by default.
Comment #103
star-szrThis is not an inline template, it's a regular template which goes through the whole theme system. Renderer, preprocess etc.
Just a thought but would it make sense to use the safe join filter instead of a for loop? Might be worth a trial/comparison for perf.
Comment #104
alexpott@Cottser but we can still use a theme function instead right - like we do for other performance related templates?
Comment #105
joelpittetWe are really trying to go to templates for a consistant dx when looking for marking up variables. Didn't win everywhere, but still trying.
Only two theme conversions blocked on performance: theme_indentation and the views fields
Comment #106
star-szrIf we're leaning towards a theme function I'd probably rather we just used an inline template (or maybe better yet, safe join in the template if feasible) if that brings the overhead down to something deemed more reasonable.
Comment #107
wim leersWhile we're very surprised that a single, simple Twig template costs us 4 ms (on the first use), that pretty much implies every other Twig template takes >= 4ms.
So… is this really that big of a deal? And did we even know about this "4 ms/unique template" rule-of-thumb?
Comment #108
joelpittetWe've been going off a rough less than 1% regression(mostly wall time) if it's not admin facing and with scenario that is common for that template when doing our performance tests with xhprof.
The worst offender was the small but repeated templates or many calls to twigs attribute.
Worst performance that got in that we profiled was not twig but #type table conversion on the simple test table of 30-40% regression but it got rammed through...
Twigs mega patch was ~10% which is what triggered the performance gate applied to all conversions, then reduced to non-admin conversions.
Comment #109
joelpittetTwigs c extension will speed up twigs attribute() calls, which iirc is all it does. And also why safe_join would be faster as cottser suggested
Comment #110
stefan.r commentedWe discussed this on IRC and likely an inline template or a safe join won't make any difference in terms of performance. Maybe we could go with a theme hook?
Comment #112
stefan.r commentedDidn't mean to remove the item list empty tests, just the inline list ones.
Comment #113
stefan.r commentedJust wondering, do we have to do an
Xss::filterAdmin()on the imploded string, even if the glue and the string are already safe?Comment #114
alexpottre #113 nope we don't.
Comment #115
alexpottSo the theme function does not seem to make much difference to the compiled template. Doing the same test against #112
I'm inclined to think we should stick with twig template and accept the cost. It also makes me wonder about the profiling of theme_indentation vs the twig template.
Comment #116
dawehnerWhat about adding a comment explaining that you better don't use it, but rather implode directly in a template?
Comment #117
stefan.r commentedSo 3.7ms always for a theme hook vs 20ms first and once the renderer is primed .8ms for a twig template?
Why is it still slow with a theme hook, have we profiled this to see if there are there any particularly inefficient/slow functions calls during rendering?
Comment #118
alexpott@stefan.r the 20ms was without opcode cache. I didn't bother profiling the theme hook without opcode cache.
Comment #119
wim leersSo 4ms with Twig template, 3.7 ms with theme function. So basically the same. That's very interesting. I too am surprised that a simple theme function is basically equally fast/slow.
Really looking forward to @Fabianx' opinion about this :)
Comment #120
stefan.r commentedApparently the 20ms included some theme initialization which we do on every request anyway, doing
Drupal::service('renderer')->renderPlain( ['#theme' => 'inline_list', '#items' => $items]);20 times in a row without opcache I get:ThemeManager::initTheme(): ~50msWhen I enable opcache these actually all go up by a bit so something may be wrong on my setup :)
Comment #121
xjmDiscussed with @alexpott and @stefan.r. The scenarios we will profile are:
Scenario A
admin/structure/views.Scenario B
admin/structure/viewsPatches to profile
Comment #122
dawehner... I would recommend to init the theme before the benchmark code.
The theme manager potentially has to initialize the entity system (due to access checking for example), which then is really costly.
Comment #123
xjmAlright, discussed with Moshe and tlittlefield, and Moshe's recommendation was that this is not worth profiling unless we put it on something like nodes, comments, etc. So we should go ahead with whatever approach has the best themer and developer experience.
Comment #124
stefan.r commentedre-uploading #93 as that seems to be what was preferred (and RTBC'ed) earlier on
Comment #125
stefan.r commentedAnd just for future reference, the benchmark script used in #120
Comment #126
wim leersAlright — sorry for the distraction!
Comment #127
star-szrThanks, all.
Comment #128
xjmNice, this looks like a great solution. Thanks also for looking into the performance concerns. Couple smallish points of feedback:
The comment says "some HTML (such as
<br />)" which would imply that it's not just<br />... but it is just<br />.Also,
<br />tags seem inherently not inline to me. They're also less semantic than lists or commas. There are also no usecases in core. So I'm not clear on why we need to support that.Finally, I'm also hesitant as to whether we need to support multiple separators at all. All of the four issues in core use commas and it seems like the majority usecase. Could we at least default to a comma if the separator is not provided? Edit: It looks like we are actually providing the comma as a default; can we document that in the preprocess docblock?
This is... odd. We don't usually link change records from API docs since change records are not permanent documentation. I also don't understand what relevance this change record has when visiting it. At a minimum, we should explain WHY the developer might want to read this link, but do we need it at all?
Comment #129
stefan.r commentedRegarding the @see, that must have sneaked in while people copypasted the preprocess for theme_item_list() (ie _item_ list)
I agree
<br />is not inline, and people should use lists for that in most cases, so we can probably remove that until there is an actual use case.Comment #130
stefan.r commentedComment #131
stefan.r commentedHm that preprocess is wrong, it just needs to Html::escape() or filter if unsafe
Comment #133
alexpottI don't think we should be supporting empty text.
Given that we're not going to be supporting
br(which seems fine). Why don't we go the whole way and just limit this to comma lists and then we'll never have to filter the or escape the comma because it'll be hardcoded?Comment #134
stefan.r commentedComment #135
joelpittetFine with not supporting empty, just thought what a great opportunity to show off that front end syntax-sugar. Mostly because the use-cases may be slim to none.
I'm a bit concerned about not doing the
<br>tags though because we have a use-case or two for that even in core on the list.<br>is not a block HTML tag, it's an inline tag, it just breaks the line. I can see how that can get look like it's not inline, but it is. Here's a nice little note on that:http://stackoverflow.com/questions/1369234/are-hr-and-br-inline-or-block...
http://htmlhelp.com/reference/html40/inline.html
Comment #136
joelpittetThe one I was refering to that exists in core is #2550985: Remove SafeMarkup::set in _batch_test_finished_helper() but I was thinking ahead to help consolidate views UI @see screenshot in #74
Comment #137
stefan.r commented@joelpittet there was a patch in #134, did you mean to set this to NW?
As to your point about "inline-ness", I can understand that "inline" applies to br elements, but I'm not sure that "list" does necessarily? It's not exactly semantic markup to use it for a list, nor is it very accessible, and I wonder if core has any valid use cases for this at all? #2550985: Remove SafeMarkup::set in _batch_test_finished_helper() looks like it should be using
<ul>.Even having looked at #74, I can't really come up with a use case for contrib modules to want to use another separator for an inline list (other than
<br />), but for those cases they should almost always be using a<ul>instead anyway. If anything we could make another template for those cases later? Things that are separated by<p>or spaces don't really sound like inline lists to me.As to the patch in #134, I agree with @xjm and @alexpott that hardcoding the separator as a comma makes sense as it would cover most use cases (at least for core). Which means we could probably also rename it to
comma_list.Comment #138
joelpittet@stefan.r yes, not a fan of removing the separator, nor the new name for the theme function.
Comment #139
joelpittetRe #137 for a list:
I think that applies to what we are trying to make here.
Comment #140
xjmI'd be okay with supporting non-markup separators and letting Twig escape them, defaulting to
,. Or with doing it in CSS, actually. I really would prefer not to add<br />to the scope though because it's not good practice.Comment #141
joelpittetI'd rather not do this template if it's only usefulness is to do what
implode()does but without the extension.I can can concede the
<br>removal as it removes the preprocess anyways and the only use-case currently is a poorly written test. Also if anybody wants they can extend their preprocess in their theme to support other things very easily.I'd like to keep 'inline_list' as the name, can that work?
Comment #142
stefan.r commentedLet's!
Comment #143
stefan.r commentedComment #144
stefan.r commentedComment #147
stefan.r commentedComment #148
stefan.r commentedSo just to summarize, #147 is essentially the same as #93 but without the empty message and without linebreak support...
Comment #149
joelpittetThank you, re-RTBC, hope (most) everybody agrees.
Comment #150
star-szrYup, I'm good with that too.
Comment #151
alexpottThe more I think about the more I think it is absolutely absurd to have a themeable comma separated list in core and that when it is used will add at least a couple of 2ms to a response. Do we need ever to customise how a comma separated list looks? Also we have a performant safe alternative in #2554073-12: Allow #markup to be an array of strings and join them safely that is only 4 times as slow as an implode + escaping whereas this is about 17 times as slow.
Comment #152
catchI would have expected this to use a
<ul>with inline styling.Having the list themed as a literal comma separated list seems like it would be an issue for RTL languages.
See for example http://www.oxwall.org/forum/topic/10218 and http://blogs.transparent.com/arabic/punctuation-in-arabic/
If we use a ul with inline CSS styling (like this very old alistapart post: http://alistapart.com/article/taminglists), then an RTL stylesheet should be able to handle it.
With the comma being in the actual markup we print, afaik that's not possible at all.
So I also disagree with the new theme hook, although I'm not sure #2554073: Allow #markup to be an array of strings and join them safely is actually right for this case either.
Comment #153
stefan.r commentedComment #154
catchstefan_r pointed out in irc why the non-semantic list is bad for screenreaders: http://www.idpf.org/accessibility/guidelines/content/xhtml/lists.php - comes down to being able to skip easily backwards and forwards through the list. Combined with my RTL concern (which I'm not 100% sure is right, but seems valid as far as I understand it), using a semantic list feels right here.
So I think we can do this:
Use 'item_list' - no extra template.
Add 'inline' and 'comma-separated' classes - we already have some CSS for inline lists (to support theme_links which also uses a semantic list for inline links), we'd need a new bit of CSS for the comma-separated bit.
Comment #155
stefan.r commented+1 to this, this relieves us of the need for a new twig template for what can be done in CSS in a much more accessible way.
As to the performance hit vs faster options, it's probably 1ms/2ms max in most scenarios considering the benchmarks in #2554073: Allow #markup to be an array of strings and join them safely. It was also pointed out that if we re-use the item list template, once that template is primed all other calls are cheaper.
Comment #156
wim leers+1. This seems like a well-balanced approach. Front-end folks are happy because it's a consistent (Twig-based) approach, accessibility people are happy because it's fully accessible.
In IRC, the following URL was also surfaced: https://stackoverflow.com/questions/1517220/how-to-style-unordered-lists...
Comment #157
stefan.r commentedRegarding configurable separators (#74.3): in those cases maybe we can re-use the pattern from this issue and make the CSS class configurable instead. A comma class will likely cover 90%+ of use cases, for the other ones we can add new classes as needed?
Comment #158
stefan.r commentedComment #159
wim leersLooks great!
I think (but am not sure!) we want
ul.inline.comma-listhere instead?(Because only
ul.inlines are eligible to become comma lists.)Comment #160
stefan.r commentedComment #161
stefan.r commentedTo me this looks the same before and after, maybe someone can confirm by going to admin/structure/views and comparing with and without the patch in #160:
With patch:
Without patch:
Comment #162
stefan.r commentedRemoving units from margin
Comment #163
stefan.r commentedAdded RTL support:

Comment #164
wim leersHrm, why only for RTL? I think this is missing the non-RTL selector?
Comment #165
davidhernandezThis looks overly specific. Shouldn't need the ul or two class names to do this.
I don't think the links css file is the best place for this. Wouldn't it be better in item-list?
...especially, if you are specifying ".item-list" but that doesn't seem necessary either.
Comment #166
stefan.r commentedIt's overriding the rtl selector only, ltr doesnt need it on the ul
Comment #167
xjmYes! This is what I expected when I first proposed the issue; glad to see it is indeed possible. Thank you!
Edit: I have no idea regarding the proper placement of the CSS under our new standards.
Comment #168
wim leersTwo spaces here, should be one.
Good point!
Well, it's currently explicitly designed to work for
#theme => item_list, but I think you're right, it doesn't need that. It'd be perfectly valid for somebody to create markup without#theme => item_list— as long as it's an<ul>with both theinlineandcomma-listclasses, it should work.So, disregard the previous point, we can keep it in this CSS file, but should remove the
.item-listparts of the selectors.The
comma-listclass only makes sense oninline<ul>s, so this does make sense. But perhaps it should beinline--comma-list, for BEM compliance?We do want
ulto be present in the selector, for consistency withul.inline.Comment #169
stefan.r commentedTo be discussed in a follow-up: maybe we shouldn't be hardcoding the classes in the calling code, we can do that in the preprocess. I'd rather see something like
'#list_type' => 'comma'.Comment #170
stefan.r commentedRemoved the item-list selector as it was not needed. I think the
item-list.theme.cssis actually better suited than thelinks.cssone, but ideally this should be in its own file. Maybe follow-up material :)As to what to call the classes, I could live with
inline--comma-listif we had #169, but now that calling render arrays have to hardcode the classes and spell them out,comma-listmay be better.@WimLeers / @davidhernandez it would be good to hear if we're good in terms of CSS now.
Comment #171
davidhernandezSo really this logically (ha!) should be a variant of the item list, which was in the patch at one point. Having a item-list--comma template somewhere, because this is a variation of the item list itself, not a variation of the contents of the list. But, whatever, that would just be a change to satisfy some css/bem dogma. I'm not suggestion we bother for such small use case.
I think
.item-list__comma-listshould be fine. It's attacking the subelement of the component, instead of a variation of it. I don't see any need for the word "inline". Isn't that kind of by definition of a comma list? I also still don't see a reason for theul.The ul isn't providing any more semantic meaning. You can try it, but it shouldn't matter, and it is better to be less specific. Even if someone changed it to an ol or nested divs or something, so what. They'd have to adjust it anyway.Comment #172
stefan.r commented"inline" was just taking advantage of the existing inline class, but we don't need it necessarily, nor do we need the ul target.
As to whether we had a variation of item-list in the patch at some point --- we didn't, we just had a
comma-listtwig template (#134). Also it's better for this not to be a variant for performance reasons, we'd rather reuse a template already used on the same request (see benchmarks in #2554073: Allow #markup to be an array of strings and join them safely).@davidhernandez told me he'd roll a new patch so I'm leaving this issue be this for now :)
Comment #173
davidhernandezI've made the unfortunate mistake of ...thinking about it.
1) The CSS should be in a separate file, not item-list.css. Probably item-list.module.css. The reason being that the .theme file will get moved to Classy and the more I think about it this the comma list is functional, not stylistic. This should work for core and live in core. The CSS should be overridable, but considered functional, so it needs to stay in core.
2) We hate when class names are added in php. We should pass the list type to the template and produce the class in the template. This makes it possible to create other list types without any modification. It also makes it overridable from the template without modification in preprocess or someplace else.
I'm going make the CSS changes and post that, in case everyone hates the idea and doesn't want to make any template changes. Buuut ... while looking I think I found something to make this easier. I'm going to check that first. Also, I think I found some visual regression in Bartik that we might want to deal with.
Comment #174
davidhernandezI was looking to change this to use a variable for the template and realized Cottser is a genius! item_list already has a generic context variable which was needed to customize the search results item_list, so I reused it. Forward thinking reusability win! \o/
The CSS is actually a bit of a conundrum. This can't really be done right without making some out of scope changes which I don't want to do and muddy up this issue. So I left the CSS in the item-list.theme.css file. We can try to fix it later when the files are moved to Classy. There were also a couple of visual regressions in Bartik and with some of the RTL. I checked all themes LTR and RTL and it looked ok to me. I also ditched the inline class. It is mostly designed for things like tabs and requires doing more overridding than necessary so why bother? All we need it for is the display: inline. The same with the uls. I can't leave them out because of Seven's styling, but need the CSS to be in Classy first before cleaning that up. Again out of scope.
Comment #175
stefan.r commented@davidhernandez nice work!
this is indented by 1 space only, shouldn't it be 2?
Also, rather than reuse the context variable isn't it better DX to create a new variable so we can do something shorter, ie.
['#list_type' => 'comma']as opposed to['#context' => ['list_style' => 'comma-list']]-- the latter mixes underscores and dashes and sounds very presentation/CSS-specific to be putting in the calling code (which will often be not be written by themers)Comment #176
wim leers@davidhernandez++
I don't see this?
But David said that it's designed to work this way:
So, given that this works in the way that the Twig people designed it to work, I think any discussion regarding improving that design should be done in a follow-up. This now complies with the latest front-end (Twig & CSS) standards, which is what this issue was stuck on.
Hence: RTBC :)
Awesome work everyone!
Comment #177
stefan.r commentedFair enough, RTBC++ then, assuming this has been manually tested?
The indentation can be fixed on commit:
Comment #178
alexpottWe've definitely had a good discussion on this one. We've arrived at the best solution wrt to semantics and accessibility. Additionally the item list is a really common template and performance cost of re-using a template already used on the page is minimal so this will be as performant as it can be. Nice work everyone.
Committed c7ca868 and pushed to 8.0.x. Thanks!
Fixed on commit - global variable unused.
Comment #179
stefan.r commentedI don't think this has been pushed yet?
Re #177, I just manually tested and it looked great!
Comment #181
star-szrReally cool to see how this came together, IMO a great example of how pushing each other to find a better solution can be really fruitful! Thanks all.
Comment #182
wim leersAbsolutely!
Special thanks to @davidhernandez on this one :)
Comment #183
davidhernandez#contextis intended for miscellaneous template things, so putting something a little more frontend friendly in there should be ok. I agree having it separated as its own variable would be better if this was intended for anything else., but the list style isn't data or state or really anything other than template context.I thought about making the value more consistent with other things we do in the backend, but that would probably mean using a space. And then using the
clean_classfilter on it in the template. Given how much discussion has gone into the performance, I didn't want to introduce another function call just for this.I'll make a comment on the issue we have open to move the item list CSS to Classy regarding some of the CSS refactoring.