Closed (fixed)
Project:
Drupal core
Version:
8.5.x-dev
Component:
render system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Jul 2017 at 16:25 UTC
Updated:
24 May 2022 at 05:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
manuel garcia commentedComment #4
manuel garcia commentedOk clearly i got too excited. Let's try this again...
Comment #5
amateescu commentedLet's not abuse the
preRenderGroup()method and just add a newpreRenderContainer()one like\Drupal\Core\Render\Element\Details::preRenderDetails().And we also need test coverage :)
Comment #6
amateescu commentedComment #7
manuel garcia commentedThanks @amateescu for the review, all good points.
Here is a patch addressing #5 and adding a WIP render test.
I believe the test cases are ok, but the test itself is not correct... I only seem to get the result of rendering what's inside the container, but not the wrapping divs around it, any clues how to do this properly? Unfortunately there is no test coverage for
Details::preRenderDetailsto have a look at.Comment #9
manuel garcia commentedAlright I can't figure that one out, so taking a different route now by defining a new BrowserTest instead.
I'm getting a weird
InvalidArgumentException: Invalid database prefix: in Drupal\Core\Test\TestDatabase->__construct() (line 81 of /var/www/drupal8/core/lib/Drupal/Core/Test/TestDatabase.php).error locally on all tests making use ofform_testmodule, hoping it's just me, let's see what the bot says...Comment #10
manuel garcia commentedComment #12
manuel garcia commentedOK at least its only me with the errors. Hopefuly this will come back green.
Any clue why somone would get this error?
Comment #14
manuel garcia commentedOK this is embarrassing... let's try it again.
Comment #16
manuel garcia commentedOK the failure seems correct, so it looks like we need to have a look at
preRenderContainer.That said I cannot work on this until I can actually run the test locally (see #12), so essentially I'm blocked.
Comment #17
manuel garcia commentedOK did a bit of thinking, and decided to try this,
Containeris not the same asDetails, so I think doing it like this makes more sense since you can just add child elements directly under the container in the array.Also, please keep in mind that I am still unable to run this test locally, so I have to rely on the bot's feedback :)
Comment #19
manuel garcia commentedPerhaps #17 wasn't such a good idea... can't really do much else here sorry, but we should continue from #14.
Comment #20
amateescu commentedActually, the logic in #17 is spot on! The only problem is that the test is missing the point of "visible" children:
\Drupal\Core\Render\Element::getVisibleChildren()does not refer to elements which print some markup or not, it is about visible render arrays.You can see the test coverage from
\Drupal\Tests\Core\Render\ElementTest::testVisibleChildren()and\Drupal\Tests\Core\Render\ElementTest::providerVisibleChildren()about what exactly is a visible render element :)Comment #21
manuel garcia commentedOH I get it... also had a look at
Element::isVisibleElement, which helped finally clear this out for me.So a visible element has nothing to do with whether or not when you render the element it actually produces any markup. A visible element is just an element who's
#typeis nothidden,valuenortoken, and that if it has an#accessproperty, it is (or returns)TRUE.Thanks so much @amateescu for helping out on this, much appreciated!
I think we're good to go with this now :D
Comment #22
dawehnerNitpick: Let's document its an array.
This introduces
'#optional'as a new feature, so let's add a change record, but also maybe add the default value to\Drupal\Core\Render\Element\Container::getInfo? On top of that I'm wondering whether we should skip if there is any value already set in'#printed'Note: You can store the result of assertSession() in a variable. I've seen @larowlan requesting it before.
\Drupal\Core\Render\Element\Actions::getInfoinherits from container, so should it inherit this pre_render function as well?Comment #23
manuel garcia commentedThanks @dawehner for the review!
#22.1 Done
#22.2 All makes sense to me, Code changes done, change record coming soon.
#22.3 Done
#22.4 Don't see why not, done.
Comment #25
manuel garcia commentedMissing comma... oops!
Added CR: https://www.drupal.org/node/2895127 :)
Comment #27
manuel garcia commentedIt's good to have tests. Fixing logic introduced in #23...
Comment #28
vijaycs85probably rephrase to say "should render" instead of "should not"?
Now makes me wonder why don't we have '#printed' check on details (i.e. core/lib/Drupal/Core/Render/Element/Details.php:87)
probably add child like normal do? i.e. $form['container_name']['child_1_name']?
Manuel Garcia++ for extensive test coverage.
Comment #29
manuel garcia commentedThanks @vijaycs85 for the review!
Re #28:
#printedprevents unneeded calls toElement::getVisibleChildren(), so we should do that inDetailsas well. Probably doesn't occur too often but every little bit counts I suppose. Either way, not in scope here =)Comment #30
amateescu commentedFWIW, I don't agree that we should also bring the Actions element in the scope of this issue.
Missed a doxygen spot here :P
Comment #32
manuel garcia commentedYeah I guess the changes to Actions is of out of scope, and probably very rarely this would have a use-case there. We can always add it later if people want it. Removing those changes here.
I also attach a patch which we could use should we ever want to add the optional property to Actions.
Fixing also #30.2 here.
Comment #33
manuel garcia commentedUpdated the CR removing references to the Actions element.
https://www.drupal.org/node/2895127
Comment #35
manuel garcia commentedPing...
Sorry to bring this up, but it is sort of blocking #2892304: Introduce footer region to ContentEntityForm, which in turn is making us repeat unnecessary code for published check-boxes (like on #2834546: UI for publishing/unpublishing block_content blocks)... :S
Comment #36
vijaycs85Thanks @Manuel Garcia. Looks like the review comments in #28 and #30 are addressed and patch is looking good. Let's get this in!
Comment #37
lauriiiIt took me a long time to understand this issue because of the issue summary was quite confusing. For anyone revisiting this issue, reading the change record and comments #21 and #22 helped me understand the change better.
Committed cff5bad and pushed to 8.5.x. Thanks!
Comment #39
manuel garcia commentedApologies @lauriii - I should've updated the description here after #21, thanks for the extra effort in understanding the issue!
Comment #40
wim leersThis actually won't work correctly in all cases: if the sole child is a placeholder, then it is impossible to know when the container is being rendered whether it will be empty.
See #953034: [meta] Themes improperly check renderable arrays when determining visibility.
Was this considered? Should the change record and docs for
#optionalmention this?Comment #41
berdir#optional already exists for e.g details elements, I don't see why we have to solve this here. The 90% use case for this is imho within forms and conditional/access-controlled form elements
Comment #42
manuel garcia commentedYup details probably suffers from the same bug... should we be patching
Element::isVisibleElementto solve it globally? Not sure if that would tackle the problem with the themes that wim mentions. Either way, I don't think we should be fixing this here.Comment #51
quietone commentedComments #41 and #42 ask for the issue in #41 to be solved in a another issue. Adding tag for a follow up and setting to NW.
Comment #52
quietone commentedAdded a followup, #3279600: Add support for a sole child placeholder to the Container render element.
This issue was committed to 8.5.x, restoring the version and returning to fixed.
Thanks.