function EntityConverter::getLatestTranslationAffectedRevision

Returns the latest revision translation of the specified entity.

Parameters

\Drupal\Core\Entity\RevisionableInterface $entity: The default revision of the entity being converted.

string $langcode: The language of the revision translation to be loaded.

Return value

\Drupal\Core\Entity\RevisionableInterface The latest translation-affecting revision for the specified entity, or just the latest revision, if the specified entity is not translatable or does not have a matching translation yet.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityRepositoryInterface::getActive() instead.

File

core/lib/Drupal/Core/ParamConverter/EntityConverter.php, line 170

Class

EntityConverter
Parameter converter for upcasting entity IDs to full objects.

Namespace

Drupal\Core\ParamConverter

Code

protected function getLatestTranslationAffectedRevision(RevisionableInterface $entity, $langcode) {
    @trigger_error('\\Drupal\\Core\\ParamConverter\\EntityConverter::getLatestTranslationAffectedRevision() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\Entity\\EntityRepositoryInterface::getActive() instead.', E_USER_DEPRECATED);
    $data_type = 'language';
    $context_id_prefix = '@language.current_language_context:';
    $contexts = [
        $context_id_prefix . LanguageInterface::TYPE_CONTENT => new Context(new ContextDefinition($data_type), $langcode),
        $context_id_prefix . LanguageInterface::TYPE_INTERFACE => new Context(new ContextDefinition($data_type), $langcode),
    ];
    $revision = $this->entityRepository
        ->getActive($entity->getEntityTypeId(), $entity->id(), $contexts);
    // The EntityRepositoryInterface::getActive() method performs entity
    // translation negotiation, but this used to return an untranslated entity
    // object as translation negotiation happened later in ::convert().
    if ($revision instanceof TranslatableInterface) {
        $revision = $revision->getUntranslated();
    }
    return $revision;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.