Problem/Motivation

If I set the current trash context to 'ignore', the code in \Drupal\trash\Hook\TrashEntityHooks::entityQueryAlter() still alters my query. Should it return as a no-op and not add any conditions when this is the case? I'd like to just manually add $query->addMetadata('trash', 'ignore') and not have to use \Drupal::service('trash.manager')->executeInTrashContext() as a wrapper.

Steps to reproduce

$query = \Drupal::entityTypeManager()->getQuery('node');
$query->addMetadata('trash', 'ignore');
$nids = $query->execute();

Confirm that $nids does not contain any trashed node IDs.

Proposed resolution

Have \Drupal\trash\Hook\TrashEntityHooks::entityQueryAlter() return without modifying the query when $query->getMetadata('trash') === 'ignore' without having to use executeInTrashContext()

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Issue fork trash-3579836

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dave reid created an issue. See original summary.

dave reid’s picture

Title: Setting trash context to 'ignore' should not alter entity queries? » Setting Entity Query trash context to 'ignore' manually should not alter entity queries

  • amateescu committed 270783cc on 3.1.x authored by dave reid
    fix: #3579836 Setting Entity Query trash context to 'ignore' manually...

  • amateescu committed c531d69a on 3.x authored by dave reid
    fix: #3579836 Setting Entity Query trash context to 'ignore' manually...
amateescu’s picture

Status: Active » Fixed

Makes sense, merged into 3.1.x and cherry-picked to 3.x, thanks!

The test failures are unrelated :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.