- Issue created by @GreenSkunk
- Assigned to kevinquillen
-
kevinquillen β
committed 03491a46 on 1.0.x
Issue #3376677 by kevinquillen: Block with Failed Condition produce PHP...
-
kevinquillen β
committed 03491a46 on 1.0.x
- πΊπΈUnited States kevinquillen
Instead of unset the array, using #access FALSE should prevent it from showing when rendered:
if (!$visible && $all_must_pass) { $build['content']['#access'] = FALSE; }
I've updated tests to account for this, and items were not visible to me in manual testing and no logs issues were present. Give the dev release a try.
- πΊπΈUnited States kevinquillen
I checked to see if I could locate how Context handles blocks normally but could not find much. I think template_preprocess_block will be called no matter what since nothing is actually preventing the execution of that code, its tagging the render array as not being displayed. I need to review the preRenderBlock method of the
Blocks
ContextReaction plugin for some insight.Previously, the logs were occurring because 'content' was being unset from the array which resulted in "Warning: Undefined array key "content" in template_preprocess_block() ".
- πΊπΈUnited States GreenSkunk Great Valley, NY
Kevin it's a good start! This worked for the blocks but any sections with context do not seem to follow any context rules now.
Messed with Pre_Render
In /src/Utility/Visibility.php, I replaced $build['content']['#access'] = FALSE with $build['#pre_render']['#printed'] = TRUE but elements are still rendering. Maybe something else is in the pre_render array?
Stuff that I've been reading
Render Arrays section of the Render API docs β
Code Blocks.php ContextReaction - Context - πΊπΈUnited States kevinquillen
I am a little lost. I have put back $build['content'] = [] instead of unset it in the dev branch, the context rules all appear to work for section or block.
hook_preprocess_block
was only called for visible blocks. - πΊπΈUnited States amanire
I hope this isn't forgotten. The commit is an improvement but results in a couple of nested empty divs, which were visible in my theme. I'm not sure what a better solution is though. It kind of seems like a core bug to assume the existence of the
content
key? As a workaround, I added this to the theme'stheme_preprocess_block()
:if (isset($variables['content']['#access']) && $variables['content']['#access'] === false) { $variables['attributes']['class'][] = 'hidden'; }
- πΊπΈUnited States kevinquillen
That could be part of it, yes. "
content
" is typically the property name for render array data, but it could be whatever a developer specifies it as in contrib.I added this to the theme
What theme?
- πΊπΈUnited States amanire
Sorry that wasn't clear. My site's custom theme. I think with core, it would just result in
<div></div>
. In my particular case, we have an additional div in the block template which monkeyed with the spacing.