- π¨π¦Canada liquidcms
I feel like this is close to solving my issue.
I have a block inside a block placed on a node layout. I need the inner block to control visibility based on the value of a node field. I have the block visibility patch ( β¨ Add visibility control conditions to blocks within Layout Builder Needs work ) and the patch from here. When i add this hook code:
function mycustom_layout_builder_view_context_alter(&$contexts, SectionStorageInterface $section_storage = NULL, $sample = FALSE) { if (!isset($contexts['layout_builder.entity'])) { return; } /* @var \Drupal\Core\Plugin\Context\EntityContext $layout_entity_context */ $layout_entity_context = $contexts['layout_builder.entity']; /* @var \Drupal\Core\Entity\EntityInterface $layout_entity */ $layout_entity = $layout_entity_context->getContextData()->getValue(); if ($layout_entity->getEntityTypeId() === 'block_content' && $layout_entity->bundle() === 'layout_block') { $entity = Node::create([ 'type' => 'service', ]); if (isset($entity)) { $contexts['layout_builder.entity'] = EntityContext::fromEntity($entity, 'Node'); } } }
This gives me the ability to add a field condition based off my node bundle when setting visibility of the inner block. But I don't see where, when it comes time to display the actual node, that the block has the context of the specific node it is on. And sure enough, on display, i get this error:
Error: Call to a member function getValue() on null in Drupal\entity_field_condition\Plugin\Condition\FieldValue->evaluate() (line 415 of modules\contrib\entity_field_condition\src\Plugin\Condition\FieldValue.php).
which makes sense as I would need to specify somewhere, the context from the actual node taken from route. What am i missing or is this not possible with the work being done here?