Same name and namespace in other branches
  1. 8.9.x core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::entityView()
  2. 9 core/modules/content_moderation/src/EntityOperations.php \Drupal\content_moderation\EntityOperations::entityView()

Act on entities being assembled before rendering.

See also

hook_entity_view()

EntityFieldManagerInterface::getExtraFields()

File

core/modules/content_moderation/src/EntityOperations.php, line 274

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\content_moderation

Code

public function entityView(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  if (!$this->moderationInfo
    ->isModeratedEntity($entity)) {
    return;
  }
  if (isset($entity->in_preview) && $entity->in_preview) {
    return;
  }

  // If the component is not defined for this display, we have nothing to do.
  if (!$display
    ->getComponent('content_moderation_control')) {
    return;
  }

  // The moderation form should be displayed only when viewing the latest
  // (translation-affecting) revision, unless it was created as published
  // default revision.
  if (($entity
    ->isDefaultRevision() || $entity
    ->wasDefaultRevision()) && $this
    ->isPublished($entity)) {
    return;
  }
  if (!$entity
    ->isLatestRevision() && !$entity
    ->isLatestTranslationAffectedRevision()) {
    return;
  }
  $build['content_moderation_control'] = $this->formBuilder
    ->getForm(EntityModerationForm::class, $entity);
}