Skip to content

Commit

Permalink
Merge pull request #190 from openeuropa/EWPP-0000
Browse files Browse the repository at this point in the history
EWPP-0000: Preventing crashes if index item is missing the original.
  • Loading branch information
upchuk authored Sep 6, 2023
2 parents dbc3b15 + fd2ba08 commit 09f4ea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ public function getLinks(int $limit = NULL, int $offset = 0): LinkCollectionInte
}

foreach ($results->getResultItems() as $item) {
$entity = $item->getOriginalObject()->getEntity();
try {
// Do not crash the application in case the index still has an item in
// it pointing to an entity that got deleted.
$entity = $item->getOriginalObject()->getEntity();
}
catch (\Exception $exception) {
continue;
}

/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->entityRepository->getTranslationFromContext($entity);
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
Expand Down
8 changes: 7 additions & 1 deletion src/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ public function buildList(ListPageConfiguration $configuration): array {
// Build the entities.
$builder = $this->entityTypeManager->getViewBuilder($configuration->getEntityType());
foreach ($result->getResultItems() as $item) {
$entity = $item->getOriginalObject()->getEntity();
try {
$entity = $item->getOriginalObject()->getEntity();
}
catch (\Exception $exception) {
continue;
}

$cache->addCacheableDependency($entity);
$entity = $this->entityRepository->getTranslationFromContext($entity);
$items[] = $builder->view($entity, $view_mode);
Expand Down

0 comments on commit 09f4ea3

Please sign in to comment.