- leymannx Berlin
Seems only enabled blocks have a weight, so I did it like this:
{% if drupal_entity('block', 'volcano_search_autocomplete')['#weight'] is defined %} ... {% endif %}
Thanks @leymannx,
I face the same issue, and the solution is what you said: the array returned indrupal_entity('block', 'mytheme_my_block_id')
is a bigger array when enabled than disabled.Here is an example dump (with my custom 2 menus):
// Disabled block ^ array:1 [▼ "#cache" => array:3 [▼ "contexts" => array:2 [▼ 0 => "url.path" 1 => "languages:language_interface" ] "tags" => array:1 [▼ 0 => "config:block.block.menushop" ] "max-age" => -1 ] ] // Enabled block ^ array:3 [▼ "#cache" => array:4 [▼ "keys" => array:3 [▼ 0 => "entity_view" 1 => "block" 2 => "menuprincipal" ] "contexts" => array:3 [▼ 0 => "languages:language_interface" 1 => "route.menu_active_trails:main-menu" 2 => "url.path" ] "tags" => array:3 [▼ 0 => "block_view" 1 => "config:block.block.menuprincipal" 2 => "config:system.menu.main-menu" ] "max-age" => -1 ] "#weight" => -16 "#lazy_builder" => array:2 [▼ 0 => "Drupal\block\BlockViewBuilder::lazyBuilder" 1 => array:3 [▼ 0 => "menuprincipal" 1 => "full" 2 => null ] ] ]
I don't know on what I'd rather do the condition:
- Check the size of the array?
- Check the definition of '#weight' and '#lazy_builder' ?
We don't know how that will evolve, so that's why it will be better to have a true boolean value to indicate this status.
What do we do now?