You are here

public function EntityOperations::entityView in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 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 234

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;
  }
  if ($this->moderationInfo
    ->isLiveRevision($entity)) {
    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'];
    $build['workbench_moderation_control']['#access'] = $this->currentUser
      ->hasPermission('moderate entities that cannot edit') || $entity
      ->access('update');
  }
}