You are here

public function EntityOperations::entityView in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 src/EntityOperations.php \Drupal\workbench_moderation\EntityOperations::entityView()

Act on entities being assembled before rendering.

This is a hook bridge.

See also

hook_entity_view()

EntityFieldManagerInterface::getExtraFields()

File

src/EntityOperations.php, line 216

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\workbench_moderation

Code

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'];
  }
}