TrashHelperTrait
Provides a helper to run code that should include trashed entities.
This is safe to use whether the Trash module is installed or not.
- Full name:
\Drupal\helper\TrashHelperTrait
Properties
includeTrash
Flag if trashed entities should be included.
protected bool $includeTrash
Methods
includeTrashedEntities
Sets a flag to include trashed entities.
public includeTrashedEntities(bool $include = true): $this
Parameters:
| Parameter | Type | Description |
|---|---|---|
$include |
bool | |
| TRUE to include trashed entities, or FALSE to skip them. |
skipTrashedEntities
Skip trashed entities.
public skipTrashedEntities(): $this
executeIgnoringTrash
Executes a callback in the trash 'ignore' context.
protected executeIgnoringTrash(callable $callback): mixed
Entity queries and loads inside the callback will include entities that are in the trash. The previous trash context is restored afterwards. If the Trash module is not installed, or trashed entities are skipped with ::skipTrashedEntities(), the callback is called directly.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$callback |
callable | |
| The callback to execute. |
Return Value:
The return value of the callback.
See Also:
- \Drupal\trash\TrashManagerInterface::executeInTrashContext()