Trigger Rabbit Hole rules on unpublished nodes

Created on 4 April 2018, about 6 years ago
Updated 28 January 2023, over 1 year ago

Rabbit Hole is a gem of a module. I wonder if it is also possible to trigger Rabbit Hole rules when accessing unpublished nodes.

Currently as soon as a node is unpublished Rabbit Hole rules ain't triggered anymore. Instead a mere 403 gets returned. Which is not very nice in terms of SEO.

Of course there's already a module for that https://www.drupal.org/project/unpublished_nodes_redirect β†’ . This one hooks into hook_menu_alter() to fire its callback. Rabbit Hole hooks into hook_node_view() for nodes.

I guess hook_node_view() is already too late to figure out if a node is unpublished and fire Rabbit Hole accordingly, am I right?

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
  • Issue was unassigned.
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    First of all, we need to figure out the main issue and the reason for the issue.
    This happens because the entity access check for the canonical route returns FALSE when the node is Unpublished.
    But this means that we will have completely the same issue for the canonical routes when users don't have permission to view the entity. It could be any entity type: node, term, group, etc.

    So first we need to determine what exactly we need to fix:
    1. Just the case with Unpublished content - if so, we can use a solution from #5.
    2. If we need to fix the general case with canonical routes access check, then we need:
    - create a new setting option - Ignore default permissions and use only rabbit hole rules when it's enabled for the bundle.
    - make route subscriber remove all access checks β†’ and set the custom one (_custom_access) that will always allow access when rabbit hole enabled for the bundle. Access check must be only one in this case, because AccessManager::check() concatenates all access results with andIf(), so any other callback can break the logic.
    - in this case, only rabbit hole rules will be working.

    Risks and comments for both cases:
    1. We need to remember, that it could be a custom entity, with custom permissions for the canonical routes, or it could be some contrib module, that provides extra permissions, e.g. https://www.drupal.org/project/permissions_by_term β†’ . So, not sure why we need to fix the issue only for the unpublished nodes if we can create new extra permission for the unpublished content instead and allow access to them.
    2. This is the best option in terms of universality. But it could be risky. If we will decide to provide this way, then we have to highlight this option with attention, that default permissions will be overridden by the rabbit hole module for the certain bundle.

Production build 0.69.0 2024