Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityOperations.php

function 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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal