Problem/Motivation
Referenced block entities (not content blocks) do not show up when rendered UNLESS they are visible anyway in some region.
This is due to access and visibility check.
Proposed resolution
Add an entityreference formatter option "ignore access checks" that opens a sitebuilder the possibility to solve this.
Remaining tasks
Check if this is feasable.
Hack it.
User interface changes
Additional formatter option.
API changes
TBD
Data model changes
TBD
Original Report
When an entity reference field references a block, and the field formatter is set to render item, the block will only be visible if it is already placed in a region on the theme block administration page. It should be possible to view the block even if the block is not generally visible in a region.
Steps to reproduce:
- Create a entity type (node, taxonomy term, block etc.) with an entity reference field
- Set target entity type to block
- Set field formatter to rendered entity
- Create a custom block that is not visible in a theme region
- Reference the block from your content type
- The referenced block will not be visible
This can be useful in many cases. I need it to create blocks with tabbed content (blocks within a block).
The reason for the problem is that the block module checks for each block's status. If it is not active in the current theme, it will be marked with status = FALSE. Then in the access check of the block module the access to the block is not permitted and the block is not rendered.
It is pretty easy to make a fix for this by implementing hook_ENTITY_TYPE_load() and set status to TRUE. However, I think a better way is to change core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php to set the status to TRUE if the entity has the setStatus method enabled. But this approach does not work as the access to the block has already been checked and cached. So it would be necessary to invalidate the cache.
Can anybody see a nice solution to this?