Dear Drupal Core maintainers,
I'm facing an issue when adding a new translation for a published content. This content has no revisions, they have been deleted by a contrib module
node_revision_delete →
.
This issue is not related to node_revision_delete but it's due to a weakness when resolving the latest translation affected revision identifier in add method of ContentTranslationController:
public function add(LanguageInterface $source, LanguageInterface $target, RouteMatchInterface $route_match, $entity_type_id = NULL) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
// In case of a pending revision, make sure we load the latest
// translation-affecting revision for the source language, otherwise the
// initial form values may not be up-to-date.
if (!$entity->isDefaultRevision() && ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id, $entity->bundle())) {
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage = $this->entityTypeManager()->getStorage($entity->getEntityTypeId());
$revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id(), $source->getId());
if ($revision_id != $entity->getRevisionId()) {
$entity = $storage->loadRevision($revision_id);
}
}
// @todo Exploit the upcoming hook_entity_prepare() when available.
// See https://www.drupal.org/node/1810394.
$this->prepareTranslation($entity, $source, $target);
The getLatestTranslationAffectedRevisionId method signature is :
/**
* Returns the latest revision affecting the specified translation.
*
* @param int|string $entity_id
* The entity identifier.
* @param string $langcode
* The language code of the translation.
*
* @return int|string|null
* A revision ID or NULL if no revision affecting the specified translation
* could be found.
*/
public function getLatestTranslationAffectedRevisionId($entity_id, $langcode);
So if getLatestTranslationAffectedRevisionId method returns NULL (which is the case when no revisions exist for a specific content), it ends up to a NULL $entity variable which breaks later the prepareTranslation method.