diff --git a/src/Plugin/Field/FieldFormatter/EntityUsageAddonsFormatter.php b/src/Plugin/Field/FieldFormatter/EntityUsageAddonsFormatter.php index e32fff8..74a56f9 100644 --- a/src/Plugin/Field/FieldFormatter/EntityUsageAddonsFormatter.php +++ b/src/Plugin/Field/FieldFormatter/EntityUsageAddonsFormatter.php @@ -81,6 +81,7 @@ class EntityUsageAddonsFormatter extends BaseFieldFileFormatterBase { '#description' => $this->t('Select the fields to display.'), '#type' => 'checkboxes', '#options' => [ + 'id' => $this->t('ID'), 'entity' => $this->t('Entity'), 'status' => $this->t('Status'), 'type' => $this->t('Type'), diff --git a/src/Service/Usage.php b/src/Service/Usage.php index 5cea039..c98bc81 100644 --- a/src/Service/Usage.php +++ b/src/Service/Usage.php @@ -2,6 +2,7 @@ namespace Drupal\entity_usage_addons\Service; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\entity_usage\EntityUsage; @@ -124,8 +125,21 @@ class Usage { // Loop over every usage entry for this entity. foreach ($ids as $key => $value) { $sourceEntity = $this->entityTypeManager->getStorage($sourceType)->load($key); + if (!$sourceEntity instanceof EntityInterface) { + continue; + } + $row = []; + // Show ID field. + if (in_array('id', $showFields)) { + $row[] = $sourceEntity->Id(); + + if (!array_key_exists('id', $header)) { + $header['id'] = $this->t('ID'); + } + } + // Show Entity field. if (in_array('entity', $showFields)) { if (!empty($sourceEntity->hasLinkTemplate('canonical'))) {