From 4ce74264949a92b89a628d6c5bc876701dc2352d Mon Sep 17 00:00:00 2001
From: Dieter Holvoet <dieter.holvoet@gmail.com>
Date: Thu, 12 Dec 2024 10:07:20 +0100
Subject: [PATCH 1/2] Replace the $entity_type argument with $entity_type_id

---
 src/Routing/RouteSubscriber.php      |  2 +-
 src/TrashEntityTypeManager.php       |  2 +-
 src/TrashManager.php                 |  8 ++++----
 src/TrashManagerInterface.php        |  6 +++---
 src/TrashStorageTrait.php            |  2 +-
 src/TrashWorkspaceInformation.php    |  2 +-
 src/ViewsQueryAlter.php              |  4 ++--
 tests/src/Kernel/TrashKernelTest.php |  4 +---
 trash.module                         | 20 ++++++++++----------
 9 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index 40d85c9..0723788 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -26,7 +26,7 @@ class RouteSubscriber extends RouteSubscriberBase {
    */
   protected function alterRoutes(RouteCollection $collection): void {
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
-      if ($this->trashManager->isEntityTypeEnabled($entity_type)) {
+      if ($this->trashManager->isEntityTypeEnabled($entity_type_id)) {
         if ($entity_type->hasLinkTemplate('canonical')) {
           $base_path = $entity_type->getLinkTemplate('canonical');
         }
diff --git a/src/TrashEntityTypeManager.php b/src/TrashEntityTypeManager.php
index 96029e0..3963d3d 100644
--- a/src/TrashEntityTypeManager.php
+++ b/src/TrashEntityTypeManager.php
@@ -76,7 +76,7 @@ class TrashEntityTypeManager extends EntityTypeManager {
    */
   public function createHandlerInstance($class, ?EntityTypeInterface $definition = NULL) {
     // @phpstan-ignore-next-line
-    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($definition)
+    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($definition->id())
       && is_subclass_of($class, SqlEntityStorageInterface::class)) {
       $class = _trash_generate_storage_class($class);
     }
diff --git a/src/TrashManager.php b/src/TrashManager.php
index 34cf393..be4e910 100644
--- a/src/TrashManager.php
+++ b/src/TrashManager.php
@@ -39,15 +39,15 @@ class TrashManager implements TrashManagerInterface {
   /**
    * {@inheritdoc}
    */
-  public function isEntityTypeEnabled(EntityTypeInterface $entity_type, ?string $bundle = NULL): bool {
+  public function isEntityTypeEnabled(string $entity_type_id, ?string $bundle = NULL): bool {
     $enabled_entity_types = $this->configFactory->get('trash.settings')->get('enabled_entity_types') ?? [];
-    if (!isset($enabled_entity_types[$entity_type->id()])) {
+    if (!isset($enabled_entity_types[$entity_type_id])) {
       return FALSE;
     }
-    elseif ($enabled_entity_types[$entity_type->id()] === []) {
+    elseif ($enabled_entity_types[$entity_type_id] === []) {
       return TRUE;
     }
-    elseif ($bundle === NULL || in_array($bundle, $enabled_entity_types[$entity_type->id()], TRUE)) {
+    elseif ($bundle === NULL || in_array($bundle, $enabled_entity_types[$entity_type_id], TRUE)) {
       return TRUE;
     }
 
diff --git a/src/TrashManagerInterface.php b/src/TrashManagerInterface.php
index 7a14f17..0e3e7e1 100644
--- a/src/TrashManagerInterface.php
+++ b/src/TrashManagerInterface.php
@@ -23,15 +23,15 @@ interface TrashManagerInterface {
   /**
    * Determines whether Trash integration is enabled for an entity type/bundle.
    *
-   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
-   *   An entity type object.
+   * @param string $entity_type_id
+   *   An entity type ID.
    * @param string|null $bundle
    *   (optional) The bundle name.
    *
    * @return bool
    *   TRUE if the entity type/bundle is enabled, FALSE otherwise.
    */
-  public function isEntityTypeEnabled(EntityTypeInterface $entity_type, ?string $bundle = NULL): bool;
+  public function isEntityTypeEnabled(string $entity_type_id, ?string $bundle = NULL): bool;
 
   /**
    * Gets the IDs of all entity types which can use the Trash.
diff --git a/src/TrashStorageTrait.php b/src/TrashStorageTrait.php
index 6315e21..b6f51d1 100644
--- a/src/TrashStorageTrait.php
+++ b/src/TrashStorageTrait.php
@@ -22,7 +22,7 @@ trait TrashStorageTrait {
     $to_trash = [];
 
     foreach ($entities as $entity) {
-      if ($this->getTrashManager()->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
+      if ($this->getTrashManager()->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
         $to_trash[] = $entity;
       }
       else {
diff --git a/src/TrashWorkspaceInformation.php b/src/TrashWorkspaceInformation.php
index 3b77ca6..6c5ca25 100644
--- a/src/TrashWorkspaceInformation.php
+++ b/src/TrashWorkspaceInformation.php
@@ -61,7 +61,7 @@ class TrashWorkspaceInformation implements WorkspaceInformationInterface {
    * {@inheritdoc}
    */
   public function isEntityDeletable(EntityInterface $entity, WorkspaceInterface $workspace): bool {
-    if ($this->trashManager->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
+    if ($this->trashManager->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
       return TRUE;
     }
 
diff --git a/src/ViewsQueryAlter.php b/src/ViewsQueryAlter.php
index 3dcb4f3..bec714f 100644
--- a/src/ViewsQueryAlter.php
+++ b/src/ViewsQueryAlter.php
@@ -66,11 +66,11 @@ class ViewsQueryAlter implements ContainerInjectionInterface {
       $table_data = $this->viewsData->get($info['base']);
 
       // Skip non-entity tables and entity types without trash integration.
+      $entity_type_id = $table_data['table']['entity type'];
       if (empty($table_data['table']['entity type'])
-        || !$this->trashManager->isEntityTypeEnabled($entity_type_definitions[$table_data['table']['entity type']])) {
+        || !$this->trashManager->isEntityTypeEnabled($entity_type_id)) {
         continue;
       }
-      $entity_type_id = $table_data['table']['entity type'];
       $deleted_table_name = $relationship_table;
 
       // This is a revision table, we need to join and use the data table which
diff --git a/tests/src/Kernel/TrashKernelTest.php b/tests/src/Kernel/TrashKernelTest.php
index 738faec..7414762 100644
--- a/tests/src/Kernel/TrashKernelTest.php
+++ b/tests/src/Kernel/TrashKernelTest.php
@@ -63,9 +63,7 @@ class TrashKernelTest extends TrashKernelTestBase {
    * @dataProvider providerIsEntityTypeEnabled
    */
   public function testIsEntityTypeEnabled($entity_type_id, $bundle, $enabled): void {
-    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
-
-    $this->assertSame($enabled, $this->getTrashManager()->isEntityTypeEnabled($entity_type, $bundle));
+    $this->assertSame($enabled, $this->getTrashManager()->isEntityTypeEnabled($entity_type_id, $bundle));
   }
 
   /**
diff --git a/trash.module b/trash.module
index 48e129f..c0ebdae 100644
--- a/trash.module
+++ b/trash.module
@@ -39,7 +39,7 @@ use Drupal\views\ViewExecutable;
  */
 function trash_entity_is_deleted(EntityInterface $entity): bool {
   /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
-  return \Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())
+  return \Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())
     && !$entity->get('deleted')->isEmpty();
 }
 
@@ -53,7 +53,7 @@ function trash_entity_is_deleted(EntityInterface $entity): bool {
  *   In case of failures, an exception is thrown.
  */
 function trash_restore_entity(EntityInterface $entity): void {
-  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
+  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
     return;
   }
 
@@ -67,7 +67,7 @@ function trash_restore_entity(EntityInterface $entity): void {
  */
 function trash_entity_base_field_info(EntityTypeInterface $entity_type) {
   // Add the 'deleted' base field.
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id())) {
     $base_field_definitions['deleted'] = BaseFieldDefinition::create('timestamp')
       ->setLabel(t('Deleted'))
       ->setDescription(t('Time when the item got deleted'))
@@ -97,10 +97,10 @@ function trash_entity_access(EntityInterface $entity, $operation, AccountInterfa
  * Implements hook_entity_query_alter().
  */
 function trash_entity_query_alter(QueryInterface $query): void {
-  $entity_type = \Drupal::entityTypeManager()->getDefinition($query->getEntityTypeId());
+  $entity_type_id = $query->getEntityTypeId();
   /** @var \Drupal\trash\TrashManagerInterface $trash_manager */
   $trash_manager = \Drupal::service('trash.manager');
-  if (!$trash_manager->shouldAlterQueries() || !$trash_manager->isEntityTypeEnabled($entity_type)) {
+  if (!$trash_manager->shouldAlterQueries() || !$trash_manager->isEntityTypeEnabled($entity_type_id)) {
     return;
   }
 
@@ -134,7 +134,7 @@ function trash_entity_query_alter(QueryInterface $query): void {
 function trash_query_search_node_search_alter(AlterableInterface $query) {
   /** @var \Drupal\Core\Database\Query\SelectInterface $query */
   $entity_type = \Drupal::entityTypeManager()->getDefinition('node');
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id())) {
     // The core Search module is not using an entity query, so we need to alter
     // its query manually.
     // @see \Drupal\node\Plugin\Search\NodeSearch::findResults()
@@ -210,7 +210,7 @@ function _trash_generate_storage_class($original_class, $type = 'storage') {
 function trash_entity_type_alter(array &$entity_types) {
   /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
   foreach ($entity_types as $entity_type_id => $entity_type) {
-    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
+    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type_id)) {
       if (!$entity_type->getFormClass('restore')) {
         $entity_type->setFormClass('restore', EntityRestoreForm::class);
       }
@@ -263,7 +263,7 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
     $entity_type = $entity_type_call->call($form_object);
     $bundle = NULL;
   }
-  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type, $bundle)) {
+  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id(), $bundle)) {
     return;
   }
 
@@ -306,7 +306,7 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  * Implements hook_entity_operation_alter().
  */
 function trash_entity_operation_alter(array &$operations, EntityInterface $entity) {
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType()) && trash_entity_is_deleted($entity)) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId()) && trash_entity_is_deleted($entity)) {
     $operations = [
       'restore' => [
         'title' => t('Restore'),
@@ -331,7 +331,7 @@ function trash_entity_view(array &$build, EntityInterface $entity, EntityViewDis
     $trash_manager = \Drupal::service('trash.manager');
     foreach (Element::children($build['changes']['list']) as $key) {
       $tracked_entity = $build['changes']['list'][$key]['#entity'];
-      if ($trash_manager->isEntityTypeEnabled($tracked_entity->getEntityType(), $tracked_entity->bundle()) && trash_entity_is_deleted($tracked_entity)) {
+      if ($trash_manager->isEntityTypeEnabled($tracked_entity->getEntityTypeId(), $tracked_entity->bundle()) && trash_entity_is_deleted($tracked_entity)) {
         // Highlight deleted entities in the workspace changes page.
         $build['changes']['list'][$key]['#attributes']['style'] = 'color: #a51b00; background-color: #fcf4f2;';
       }
-- 
GitLab


From ae2c7a548ff5396943a5b9ee1f5bbcf0f24b38c1 Mon Sep 17 00:00:00 2001
From: Dieter Holvoet <dieter.holvoet@gmail.com>
Date: Thu, 12 Dec 2024 11:38:14 +0100
Subject: [PATCH 2/2] Allow both objects and strings as $entity_type argument

---
 src/Routing/RouteSubscriber.php      |  2 +-
 src/TrashEntityTypeManager.php       |  2 +-
 src/TrashManager.php                 |  3 ++-
 src/TrashManagerInterface.php        |  6 +++---
 src/TrashStorageTrait.php            |  2 +-
 src/TrashWorkspaceInformation.php    |  2 +-
 src/ViewsQueryAlter.php              |  4 ++--
 tests/src/Kernel/TrashKernelTest.php |  2 ++
 trash.module                         | 16 ++++++++--------
 9 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index 0723788..40d85c9 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -26,7 +26,7 @@ class RouteSubscriber extends RouteSubscriberBase {
    */
   protected function alterRoutes(RouteCollection $collection): void {
     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
-      if ($this->trashManager->isEntityTypeEnabled($entity_type_id)) {
+      if ($this->trashManager->isEntityTypeEnabled($entity_type)) {
         if ($entity_type->hasLinkTemplate('canonical')) {
           $base_path = $entity_type->getLinkTemplate('canonical');
         }
diff --git a/src/TrashEntityTypeManager.php b/src/TrashEntityTypeManager.php
index 3963d3d..96029e0 100644
--- a/src/TrashEntityTypeManager.php
+++ b/src/TrashEntityTypeManager.php
@@ -76,7 +76,7 @@ class TrashEntityTypeManager extends EntityTypeManager {
    */
   public function createHandlerInstance($class, ?EntityTypeInterface $definition = NULL) {
     // @phpstan-ignore-next-line
-    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($definition->id())
+    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($definition)
       && is_subclass_of($class, SqlEntityStorageInterface::class)) {
       $class = _trash_generate_storage_class($class);
     }
diff --git a/src/TrashManager.php b/src/TrashManager.php
index be4e910..3d35e07 100644
--- a/src/TrashManager.php
+++ b/src/TrashManager.php
@@ -39,7 +39,8 @@ class TrashManager implements TrashManagerInterface {
   /**
    * {@inheritdoc}
    */
-  public function isEntityTypeEnabled(string $entity_type_id, ?string $bundle = NULL): bool {
+  public function isEntityTypeEnabled(EntityTypeInterface|string $entity_type, ?string $bundle = NULL): bool {
+    $entity_type_id = $entity_type instanceof EntityTypeInterface ? $entity_type->id() : $entity_type;
     $enabled_entity_types = $this->configFactory->get('trash.settings')->get('enabled_entity_types') ?? [];
     if (!isset($enabled_entity_types[$entity_type_id])) {
       return FALSE;
diff --git a/src/TrashManagerInterface.php b/src/TrashManagerInterface.php
index 0e3e7e1..d6fcbbe 100644
--- a/src/TrashManagerInterface.php
+++ b/src/TrashManagerInterface.php
@@ -23,15 +23,15 @@ interface TrashManagerInterface {
   /**
    * Determines whether Trash integration is enabled for an entity type/bundle.
    *
-   * @param string $entity_type_id
-   *   An entity type ID.
+   * @param \Drupal\Core\Entity\EntityTypeInterface|string $entity_type
+   *   An entity type object or ID.
    * @param string|null $bundle
    *   (optional) The bundle name.
    *
    * @return bool
    *   TRUE if the entity type/bundle is enabled, FALSE otherwise.
    */
-  public function isEntityTypeEnabled(string $entity_type_id, ?string $bundle = NULL): bool;
+  public function isEntityTypeEnabled(EntityTypeInterface|string $entity_type, ?string $bundle = NULL): bool;
 
   /**
    * Gets the IDs of all entity types which can use the Trash.
diff --git a/src/TrashStorageTrait.php b/src/TrashStorageTrait.php
index b6f51d1..6315e21 100644
--- a/src/TrashStorageTrait.php
+++ b/src/TrashStorageTrait.php
@@ -22,7 +22,7 @@ trait TrashStorageTrait {
     $to_trash = [];
 
     foreach ($entities as $entity) {
-      if ($this->getTrashManager()->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
+      if ($this->getTrashManager()->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
         $to_trash[] = $entity;
       }
       else {
diff --git a/src/TrashWorkspaceInformation.php b/src/TrashWorkspaceInformation.php
index 6c5ca25..3b77ca6 100644
--- a/src/TrashWorkspaceInformation.php
+++ b/src/TrashWorkspaceInformation.php
@@ -61,7 +61,7 @@ class TrashWorkspaceInformation implements WorkspaceInformationInterface {
    * {@inheritdoc}
    */
   public function isEntityDeletable(EntityInterface $entity, WorkspaceInterface $workspace): bool {
-    if ($this->trashManager->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
+    if ($this->trashManager->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
       return TRUE;
     }
 
diff --git a/src/ViewsQueryAlter.php b/src/ViewsQueryAlter.php
index bec714f..3dcb4f3 100644
--- a/src/ViewsQueryAlter.php
+++ b/src/ViewsQueryAlter.php
@@ -66,11 +66,11 @@ class ViewsQueryAlter implements ContainerInjectionInterface {
       $table_data = $this->viewsData->get($info['base']);
 
       // Skip non-entity tables and entity types without trash integration.
-      $entity_type_id = $table_data['table']['entity type'];
       if (empty($table_data['table']['entity type'])
-        || !$this->trashManager->isEntityTypeEnabled($entity_type_id)) {
+        || !$this->trashManager->isEntityTypeEnabled($entity_type_definitions[$table_data['table']['entity type']])) {
         continue;
       }
+      $entity_type_id = $table_data['table']['entity type'];
       $deleted_table_name = $relationship_table;
 
       // This is a revision table, we need to join and use the data table which
diff --git a/tests/src/Kernel/TrashKernelTest.php b/tests/src/Kernel/TrashKernelTest.php
index 7414762..7858204 100644
--- a/tests/src/Kernel/TrashKernelTest.php
+++ b/tests/src/Kernel/TrashKernelTest.php
@@ -64,6 +64,8 @@ class TrashKernelTest extends TrashKernelTestBase {
    */
   public function testIsEntityTypeEnabled($entity_type_id, $bundle, $enabled): void {
     $this->assertSame($enabled, $this->getTrashManager()->isEntityTypeEnabled($entity_type_id, $bundle));
+    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
+    $this->assertSame($enabled, $this->getTrashManager()->isEntityTypeEnabled($entity_type, $bundle));
   }
 
   /**
diff --git a/trash.module b/trash.module
index c0ebdae..d6ae652 100644
--- a/trash.module
+++ b/trash.module
@@ -39,7 +39,7 @@ use Drupal\views\ViewExecutable;
  */
 function trash_entity_is_deleted(EntityInterface $entity): bool {
   /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
-  return \Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())
+  return \Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())
     && !$entity->get('deleted')->isEmpty();
 }
 
@@ -53,7 +53,7 @@ function trash_entity_is_deleted(EntityInterface $entity): bool {
  *   In case of failures, an exception is thrown.
  */
 function trash_restore_entity(EntityInterface $entity): void {
-  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId(), $entity->bundle())) {
+  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType(), $entity->bundle())) {
     return;
   }
 
@@ -67,7 +67,7 @@ function trash_restore_entity(EntityInterface $entity): void {
  */
 function trash_entity_base_field_info(EntityTypeInterface $entity_type) {
   // Add the 'deleted' base field.
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id())) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
     $base_field_definitions['deleted'] = BaseFieldDefinition::create('timestamp')
       ->setLabel(t('Deleted'))
       ->setDescription(t('Time when the item got deleted'))
@@ -134,7 +134,7 @@ function trash_entity_query_alter(QueryInterface $query): void {
 function trash_query_search_node_search_alter(AlterableInterface $query) {
   /** @var \Drupal\Core\Database\Query\SelectInterface $query */
   $entity_type = \Drupal::entityTypeManager()->getDefinition('node');
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id())) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
     // The core Search module is not using an entity query, so we need to alter
     // its query manually.
     // @see \Drupal\node\Plugin\Search\NodeSearch::findResults()
@@ -210,7 +210,7 @@ function _trash_generate_storage_class($original_class, $type = 'storage') {
 function trash_entity_type_alter(array &$entity_types) {
   /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
   foreach ($entity_types as $entity_type_id => $entity_type) {
-    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type_id)) {
+    if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type)) {
       if (!$entity_type->getFormClass('restore')) {
         $entity_type->setFormClass('restore', EntityRestoreForm::class);
       }
@@ -263,7 +263,7 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
     $entity_type = $entity_type_call->call($form_object);
     $bundle = NULL;
   }
-  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type->id(), $bundle)) {
+  if (!\Drupal::service('trash.manager')->isEntityTypeEnabled($entity_type, $bundle)) {
     return;
   }
 
@@ -306,7 +306,7 @@ function trash_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  * Implements hook_entity_operation_alter().
  */
 function trash_entity_operation_alter(array &$operations, EntityInterface $entity) {
-  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityTypeId()) && trash_entity_is_deleted($entity)) {
+  if (\Drupal::service('trash.manager')->isEntityTypeEnabled($entity->getEntityType()) && trash_entity_is_deleted($entity)) {
     $operations = [
       'restore' => [
         'title' => t('Restore'),
@@ -331,7 +331,7 @@ function trash_entity_view(array &$build, EntityInterface $entity, EntityViewDis
     $trash_manager = \Drupal::service('trash.manager');
     foreach (Element::children($build['changes']['list']) as $key) {
       $tracked_entity = $build['changes']['list'][$key]['#entity'];
-      if ($trash_manager->isEntityTypeEnabled($tracked_entity->getEntityTypeId(), $tracked_entity->bundle()) && trash_entity_is_deleted($tracked_entity)) {
+      if ($trash_manager->isEntityTypeEnabled($tracked_entity->getEntityType(), $tracked_entity->bundle()) && trash_entity_is_deleted($tracked_entity)) {
         // Highlight deleted entities in the workspace changes page.
         $build['changes']['list'][$key]['#attributes']['style'] = 'color: #a51b00; background-color: #fcf4f2;';
       }
-- 
GitLab

