View filters on rh_action with null values in database

Created on 3 April 2025, 16 days ago

Problem/Motivation

When a user without "Administer Rabbit Hole settings for ..." creates an entity with rabbit hole settings defined, the resulting database values for "rh_action" and others are set to "NULL". This does not affect behavior on the action when viewing the entity - the Rabbit Hole Settings -> behavior is respected. However this becomes an issue if you are trying to use a view with a filter on "rh_action".

Steps to reproduce

Log in as a user with "Administer Rabbit Hole settings for Content" permission
On a node edit settings:
- Check "Allow these settings to be overridden for individual entities"
- Check "Display the Page"
Create 3 nodes
- On 2 keep " Global keywords behavior (Display the page)"
- On 1 set to "Access denied"
Create a view
- Filter by "Rabbit Hole Action" != "Access Denied"
- You should see two items as expected

Look in the database
- You should see values set for "rh_action", "rh_redirect_response", and "rh_redirect_fallback_action" on all 3 nodes in the node_field_data table.

Log in as a user without "Administer Rabbit Hole settings for Content", but with permission to add content
- Add a node

Look in the database
- You should see on the new node that "rh_action", "rh_redirect_response", and "rh_redirect_fallback_action" are all set to NULL

Reload the view
- You will NOT see your new node - even though it should inherit the global setting of "Display the page"
- This is because the view is filtering on this value, and if there is no value it gets left out (join thing? idk)

Proposed resolution

Check if the user does NOT have access, but everything else passes, then set defaults (if they are blank)

Remaining tasks

Test the fix
Test coverab

User interface changes

none

API changes

none

Data model changes

none

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States scott_earnest

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

Merge Requests

Comments & Activities

  • Issue created by @scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest

    This may be helpful to someone - we wrote an update hook to batch update records that had null values:

    /**
     * Rabbit Hole update to default for NULL values for nodes.
     */
    function MY_MODULE_update_10001(&$sandbox) {
    
      // Set array of node ids to update in sandbox.
      if (!isset($sandbox['ids'])) {
        $ids = \Drupal::entityQuery('node')
          ->accessCheck(FALSE)
          ->condition('rh_action', NULL, 'IS NULL')
          ->sort('nid')
          ->execute();
        $sandbox['ids'] = $ids;
        $sandbox['current'] = 0;
        if (empty($sandbox['ids'])) {
          $sandbox['#finished'] = 1;
          return;
        }
      }
    
      // Set batch size.
      $items_per_batch = 100;
      // Grab the working set based off of current position and range.
      $ids = array_slice($sandbox['ids'], $sandbox['current'], $items_per_batch);
    
      // Exit out if nothing to do.
      if (empty($ids)) {
        $sandbox['#finished'] = 1;
        return;
      }
    
      // Loop over node ids.
      foreach ($ids as $id) {
        $node = \Drupal::entityTypeManager()->getStorage('node')->load($id);
        // Set default values for NULL fields.
        $node->set('rh_action', 'bundle_default')
          ->set('rh_redirect_response', 301)
          ->set('rh_redirect_fallback_action', 'bundle_default');
        $node->save();
        $sandbox['current']++;
      }
    
      // Set the return message - either in progress or finished.
      if ($sandbox['current'] >= count($sandbox['ids'])) {
        $sandbox['#finished'] = 1;
        $message = 'Batch update for missing Rabbit Hole values completed';
        $args = [];
      }
      else {
        $sandbox['#finished'] = ($sandbox['current'] / count($sandbox['ids']));
        $message = 'Progress: @count / @total';
        $args = [
          '@count' => $sandbox['current'],
          '@total' => count($sandbox['ids']),
        ];
      }
    
      // Return with message - will show progress of batch.
      return new \Drupal\Core\StringTranslation\TranslatableMarkup($message, $args);
    
    }
    
  • Pipeline finished with Failed
    16 days ago
    Total: 574s
    #464780
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest

    Sorry I don't currently have a site with Rabbit Hole v2 on it atm. Ticket will need work for that branch and testing. thanks!

  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest
  • πŸ‡ΊπŸ‡ΈUnited States scott_earnest
Production build 0.71.5 2024