Needs work
Project:
Bartik
Version:
1.0.2
Component:
Look and Feel
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Jul 2015 at 15:56 UTC
Updated:
12 Jan 2023 at 01:23 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
wim leersComment #2
fabianx commentedUnless we already formally introduced Element::isEmpty() we should add a change record as part of that issue as a special for themers one.
Being a bug this obviously needs tests.
The patch itself looks great though!
Comment #5
cilefen commentedComment #6
wim leersThanks for renaming! Just wanted to file it really quickly.
Comment #7
wim leersComment #8
fabianx commentedLets do it.
Comment #9
davidhernandez:( themer experience-- Probably out of scope here, but it would be nice if there was a helper function to handle that check instead of requiring the themer to be that specific. Especially, since there is no way to intuit that you'd have to do that.
From the change record, I don't understand what this means:
I'm not sure if I'm lacking technical clarity or if it's the construction of the sentence that is the problem.
Comment #10
wim leersTBH, the problem is really the fact that
bartik_preprocess_html()is fundamentally wrong/broken. This just makes it less broken.E.g; if
$page['some_region'] = ['#markup' => 'foobar', '#access' => FALSE], then it should not conclude that the region will be not empty. But it does.Comment #11
davidhernandez@Wim, it is carry over from the previous version. What the theme (and any theme would want to do this) is determine if the region is displayable, regardless of whether that is determined by the existence of content or access. It doesn't look like we have a proper way of doing that it seems. (at least not an ugly way)
Why would a region have access be false? Not a block or something else, but the region itself.
Comment #14
wim leersPer #953034-161: [meta] Themes improperly check renderable arrays when determining visibility, I'm not sure if we can fix this. :( I think we simply shouldn't have conditional HTML based on emptiness.
Comment #15
fabianx commentedThis should still go in as it is a large large improvement.
Only because we cannot fix all use-cases, does not mean we should not fix at least the obvious visible bugs.
Major because bartik maintainer is upset about the current behavior.
Comment #16
fabianx commentedNeeds a re-roll though ...
Comment #17
davidhernandezComment #18
fabianx commentedComment #19
alexpottThe isset() && Element::isEmpty() looks ugly.
What to do people think about making the following change:
So this would become:
Comment #20
davidhernandezI'd still prefer a simpler, non-oop, function for themers to use. It's a little much to expect non-devs to know how to intuit the syntax and know about namespaces just to add something for a region. But at least removing the double check is an improvement.
Comment #21
fabianx commentedWith my theme maintainer hat on:
I would be fine with a function like:
element_is_empty($variables, 'sidebar_second')
which calls Element::isEmpty() with the new $key functionality, which I very much like.
Lets do it!
CNW for the change and lets make Emma happy! :)
Comment #22
davidhernandezA element_is_empty function or whatever it should be named sounds good to me.
Comment #23
wim leersUnfortunately, this is an oversimplification:
Because it is actually a non-top-level child that we need to check:
$variables['page']['sidebar_first']. Fortunately, that's an easy enough change, that I think is still in line with what Alex Pott, Fabianx and davidhernandez consider an improvement:Implementing that now.
Comment #24
wim leersHere you go.
Comment #25
wim leersBut note that this patch does not actually do what you think it does. It is in fact impossible to solve.
I've explained why this is impossible to solve at #2503755-116: Switch from user login block to login menu link and search block in standard profile. Let me repeat that verbatim here:
Comment #26
fabianx commentedRTBC, thanks #23.
#25:
Yes, however because access conditions vary upwards the overall page is cached based on the variation in those conditions, which means that the sidebar is either populated or not for blocks, because their access is checked up-front and not afterwards.
Which means for bartik this all should work out well.
Only if there is a placeholder either deeper in or if the block is returned empty based on something that is not 'access' (and visibility conditions are 'access' here), then it gets to be a problem, which is way less a problem, so this should be fine for everything except those edge cases.
Comment #27
wim leersThat's not really true. See the menu block example I gave in #25. The user has access to the block itself, but turns out that they don't have access to any of the content in that block, so the block is empty after all.
So it's not just about placeholders, it's also about lazy rendering. Which is exactly the problem described in #25.
Therefore, I'm not at all certain this issue/patch is actually a step forward. I think it may actually be a step in the wrong direction.
Comment #28
wim leersAlso note that the menu block with its menu links is just one example.
Views is another example: a block display for a view could behave in the same way, depending on the "empty result set" setting (if it is configured to show something when the result set is empty, then there won't be a problem, but if a view isn't configured to show something, then it'll be the exact same problem as with the menu block above).
Comment #29
davidhernandezIf I get the gist of this, we are entering a world where the page layouts (at a high level) need to not be adapted by the backend. If any manipulation is to occur, it has to occur on the frontend. The sidebar needs to always exist in markup, in case something later gets shoe-horned into it? Things like the layout-one-sidebar classes would have to go, because at what point do we actually know, unless they are added by JS?
This would indeed be a very different world than what a lot of people are currently used to. We'll need understand this.
Comment #30
davidhernandezWe don't need this any more, right?
I'm adding needs tests, because we're adding a new api function.
Comment #31
catchThe sidebar itself could be lazy rendered if we want, but then you wouldn't know if it'll eventually contain anything or not either.
So yes in terms of the entire page layout, the only way to have those body-level classes is via js.
Comment #32
wim leers#29:
We actually can now on the server side, to some extent: if no blocks are placed in a region, that region is always going to be empty. Which actually is… almost exactly what HEAD does.
But that does mean that you can't have page-specific page-level classes: you'd either always have two sidebars, or always have one, across an entire site.
Not "would", but "is". We are already in this world. Everything is adjusted for it. Except this feature of Bartik. Because nobody who does core development ever uses both sidebars or only the second sidebar. Everybody always uses the first sidebar.
From this POV (#27 + #28 + this comment), the current patch does not make sense at all. I tries to give you a tool to pretend we're not in this "different world", even though we actually are there already, and have been for… at least a year already, and have been working towards it since almost the beginning of the Drupal 8 cycle.
Comment #33
davidhernandezBut that fact is meaningless. People aren't trying to build flexibility in case where they know they've never placed a block in a region. It is cases where a block is placed, but may not render because the content is conditional.
If the login block is in the sidebar, the sidebar appears. If I'm logged in and the login block doesn't render, I have no need for the sidebar. That is a conditional layout. I can't add "layout-one-sidebar layout-sidebar-first" at the page layer if I don't know if it is true. Those classes would be used to determine the styling of the layout; widths, margins, etc. I can completely re-theme a site with just those two classes.
I'm not sure what you are implying by this. That no one does this in the real world, or just that no one noticed a problem because most of us don't actually use Bartik for this?
Comment #34
wim leersI disagree with this. If your site has zero blocks in a certain region, then it's useful for the theme to adapt to that. It may be less valuable/flexible, but it still is valuable for the same reasons it's valuable for conditional content.
Comment #35
davidhernandezOk, I just wanted to make sure. I agree we aren't always good testing all use cases. I thought you might have been saying, "second sidebars, who does that??"
If I'm understanding correctly, you are saying in cases where no block has been configured for a region at all. Like it is empty in the block layout UI. That could be useful to know for a generic theme - one meant for distribution (like perhaps Bartik) - but much less useful for a site build. That sounds to me like a region that doesn't need to exist.
Well, what is the next step? It sounds like Bartik's CSS architecture needs to be fixed and this preprocessing removed altogether. Also, can we document the best-practice for this so people can understand why and how we should be doing this properly? I think themers can adjust if they know what to do and why.
Comment #36
wim leersAgreed!
I'm afraid that is correct… :(
I don't know what the best practice would be, only that this practice we've used in the past, and that we've used until now, does not work. I think it's up to themers in D8 to collectively define a best practice. But we should definitely recomend against what Bartik does specifically, and mark it as something to explicitly avoid.
And if we're honest, this problem actually also existed in D7, just in a less severe form, which is why #953034: [meta] Themes improperly check renderable arrays when determining visibility is a few weeks away from its fifth birthday.
Comment #37
davidhernandezShort term will the patch in #17 fix Bartik's use case, even if somewhat superficially and dismissing the lazy render issues?
I think we need some fix now that solves at least the most basic use cases for Bartik, and then deal with the CSS architectural changes later. We can do that now that Bartik is being marked @internal. A wholesale sidebar rethinking might be too much to deal with right now.
Comment #38
wim leersNo, #17 doesn't fix it at all. It only fixes the case where something is not accessible and the cacheability metadata for that thing still appears.
We can't fix it.
That's why I'm saying nobody ever tests with blocks in the second sidebar etc.
Comment #39
catchWell I think we could do a short term fix with js?
That won't work with js disabled, and it is worse for front-end performance, but for now it'd look better.
Comment #40
wim leersYep, true.
Fixing title and working on that.
Comment #41
wim leersKISS.
Comment #43
wim leersOops. Identical to the previous one content-wise, but this patch doesn't assume that Bartik already has a
layout.jsfile. Should be actually applicable.Comment #44
fabianx commentedAren't JS files in js/ subfolder per some definition?
Comment #45
davidhernandezI guess that seems ok. Emma should sign off on the library addition/changes.
Comment #49
nod_malformated dependency.
The layout-no-sidebar seemed to have been lost in the process. Used querySelector to make things nicer. And since the region format in bartik has an inner element, updated the query to make sure we count the right things. Added JSDoc, renamed the function, not a constructor so no capital letter.
I removed the early call to bartikLayoutUpdate because it'd break if that script ends up in the head at some point. Better safe than sorry and the delay doesn't show that much on stock bartik. Just keeping it simple.
Comment #52
wim leers.sectionthing doing there?querySelector()returnsNodes, notElements, so IIRC you can't just invokechildElementCounton that?Comment #53
nod_1. The selector is using whatever we tell him to. Open up bartik's page.html.twig:
Good enough for me to rely on ids for bartik.
2. see above.
3. from https://dom.spec.whatwg.org
Node and Element, same difference.
Comment #54
wim leersquerySelector(), and this was my conclusion after checking docs, but I clearly must've done something wrong :)So, other than the test failures, I think this is ready then.
Comment #55
fabianx commentedHere is another idea, which could just use CSS and keep our no-JS for anonymous users selling point.
We can use CSS :empty (http://caniuse.com/#feat=css-sel3) - provided that the space in between is not even having spaces and page.sidebar_first is truly empty after rendering.
There is two ways:
a) Use
{{- page.sidebar_first -}}- If that would work to remove all whitespace around the element that would be wonderful.b) Add a special data- attribute and have a generic FilterResponseEvent, which does a preg_replace() and removes all whitespace from a section which has that data selector - that should not be too bad performance wise and pretty easily reg-exp expressionable.
While the JS only solution works fine for bartik itself and probably other contrib themes, both these solutions would purely rely on CSS in the end just ensuring content is filtered correctly down to empty.
Edit:
Nevermind I tried that and the structure of the CSS / DOM does not allow that.
While it would be possible to target some regions in that way, it is impossible for this sidebar-first implementaton as that one relies on the content shifting itself to 75% width ...
Edit:
Any contrib theme can use display: flex and correct flex adjustments just fine with :empty, so its mainly core that needs the JS here, which should be fine ...
Comment #58
davidhernandezLike Fabian, I've been trying to find a non-JS solution. As Wim repeatedly points out, this looks impossible. (Well, I could probably work one out in just CSS if I redesign Bartik's responsive CSS.)
So if the JS solution is good to go, what do we do about the failing test? It is the "no anonymous js" test. Are we saying we have to get rid of that, or should the test be switched to use Classy and not Bartik?
Comment #59
wim leersMake the "no JS for anon" test exempt this JS" just like it exempts the HTML5 shiv.
Comment #60
nod_Does #2503755: Switch from user login block to login menu link and search block in standard profile mean we don't need to fix this properly now?
Comment #61
wim leers#60: indeed it does. Which buys us the time to fix this in a non-rushed manner, which surely is preferable :)
Comment #65
balagan commentedComment #66
balagan commentedComment #76
pameeela commentedMoving to contrib since Bartik was removed from core in D10.