Problem/Motivation
We have a quite a big problem with a next scenario. We have a node with paragraphs which can have linkit field to other nodes. If linkit node is deleted then when you view parent node next PHP fatal error is generated:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Entity\EntityRepository::getTranslationFromContext() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in.../web/modules/contrib/linkit/src/Utility/LinkitHelper.php on line 21 in Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (line 82 of core/lib/Drupal/Core/Entity/EntityRepository.php).
Drupal\Core\Entity\EntityRepository->getTranslationFromContext(NULL) (Line: 21)
Drupal\linkit\Utility\LinkitHelper::getEntityFromUri('entity:node/108') (Line: 121)
Drupal\linkit\Plugin\Field\FieldFormatter\LinkitFormatter->getSubstitutedUrl(Object) (Line: 99)
Drupal\linkit\Plugin\Field\FieldFormatter\LinkitFormatter->viewElements(Object, 'de') (Line: 80)
Drupal\Core\Field\FormatterBase->view(Object, 'de') (Line: 259)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 320)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'primer_teaser_grid') (Line: 263)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 18)
Drupal\paragraphs\ParagraphViewBuilder->buildMultiple(Array) (Line: 220)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func(Array, Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
...
The problem is in LinkitHelper::getEntityFromUri() method which will try to load entity that not exist and then pass it to the getTranslationFromContext() method, and this produce fatal error.
Proposed resolution
Propose a quick patch for now so affected sites are fixed and figure proper solution approach after it.
Comments
Comment #2
pivica commentedThis is not happening with current dev version but with the patch in #2712951: Linkit for Link field.
Marking this as a duplicate for now, will move this to the related issue.