/**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     $entity = parent::convert($value, $definition, $name, $defaults);
     if ($entity && $this->moderationInformation->isModeratedEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) {
         $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults);
         $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value);
         // If the entity type is translatable, ensure we return the proper
         // translation object for the current context.
         if ($latest_revision instanceof EntityInterface && $entity instanceof TranslatableInterface) {
             $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, array('operation' => 'entity_upcast'));
         }
         if ($latest_revision->isRevisionTranslationAffected()) {
             $entity = $latest_revision;
         }
     }
     return $entity;
 }
 /**
  * Act on entities being assembled before rendering.
  *
  * This is a hook bridge.
  *
  * @see hook_entity_view()
  * @see EntityFieldManagerInterface::getExtraFields()
  */
 public function entityView(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
 {
     if (!$this->moderationInfo->isModeratedEntity($entity)) {
         return;
     }
     if (!$this->moderationInfo->isLatestRevision($entity)) {
         return;
     }
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity->isDefaultRevision()) {
         return;
     }
     $component = $display->getComponent('content_moderation_control');
     if ($component) {
         $build['content_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class, $entity);
         $build['content_moderation_control']['#weight'] = $component['weight'];
     }
 }