Add support for block access in eca_access sub-module

Created on 26 March 2024, 3 months ago
Updated 10 May 2024, about 2 months ago

it would be nice to have support for block access in eca_access sub-module to control the visibility of content blocks like in
https://www.drupal.org/project/condition_query β†’

πŸ’¬ Support request
Status

Fixed

Version

2.0

Component

Miscellaneous

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @nojj
  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    I think what you're looking for is not block "access", but rather a "condition" plugin. This section of the manage block display shows core condition plugins that control block visibility.

    As I understand it, we could implement entity access for "content_block" entities that might allow you to show/hide blocks anywhere they appear -- but this would only apply to content_block entities, not any other type of block, or custom block plugins, or anything else.

    To control whether or not a block appears on a particular page, there are several different ways of showing blocks -- the core block system (which uses condition plugins), Layout Builder (which currently doesn't have any way to add conditions), Context, Display Suite, Panels, Twig Tweak, Ctools... Each of these has its own way of controlling whether or not to show a block.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    It seems that in addition to the block conditions, there is also the hook_block_access with this documentation:

     * Control access to a block instance.
     *
     * Modules may implement this hook if they want to have a say in whether or not
     * a given user has access to perform a given operation on a block instance.
    

    That really sounds as if we could use that hook, turn it into an event and override the access control for a specific block.

  • sounds good to me.
    willing to test ;-)

  • πŸ‡©πŸ‡ͺGermany mxh Offenburg

    It's already possible with eca_access. Attached an example model that denies access on the site branding block used in the Olivero theme.

  • Thanks @mxh
    there is a litte typo typo in the filename: tar_.gz
    but it is a great help and indeed, it is possibly to show/hide blocks with eca_access.

    maybe using hook_block_access would be a little bit more flexible, as eca_access can only react on ECA Access events.
    https://ecaguide.org/plugins/eca/access/actions/eca_access_set_result/

  • πŸ‡©πŸ‡ͺGermany mxh Offenburg

    there is a litte typo typo in the filename: tar_.gz

    That's on purpose for security reasons. d.o. automatically renames the file endings when uploading archives.

    maybe using hook_block_access would be a little bit more flexible, as eca_access can only react on ECA Access events.

    Could you please elaborate what you're currently missing?

    hook_block_access is a variant of hook_ENTITY_TYPE_access for block config entities. The eca_access module reacts upon hook_entity_access, i.e. it is basically already reacting upon that hook.

  • for my intention, I am not missing anything right now.

    "maybe" was meant more as a possible improvement - I haven't checked this. the thought just came to my mind. if the two hooks are more or or less the same, then so be it.

  • Status changed to Fixed 2 months ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024