/** * Implements hook_entity_view_alter(). */ public function entityViewAlter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { if ($entity->getEntityType()->isRevisionable() && !$this->moderationInfo->isLatestRevision($entity)) { // Hide quickedit, because its super confusing for the user to not edit the // live revision. unset($build['#attributes']['data-quickedit-entity-id']); } }
/** * 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->isModeratableEntity($entity)) { return; } if (!$this->moderationInfo->isLatestRevision($entity)) { return; } /** @var ContentEntityInterface $entity */ if ($entity->isDefaultRevision()) { return; } $component = $display->getComponent('workbench_moderation_control'); if ($component) { $build['workbench_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class, $entity); $build['workbench_moderation_control']['#weight'] = $component['weight']; } }
/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { $entity = parent::convert($value, $definition, $name, $defaults); if ($entity && $this->moderationInformation->isModeratableEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) { $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); $entity = $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 ($entity instanceof EntityInterface && $entity instanceof TranslatableInterface) { $entity = $this->entityManager->getTranslationFromContext($entity, NULL, array('operation' => 'entity_upcast')); } } return $entity; }