You are here

protected function EntityTypeInfo::addModerationToEntity in Workbench Moderation 8.2

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

Modifies an entity definition to include moderation support.

This primarily just means an extra handler. A Generic one is provided, but individual entity types can provide their own as appropriate.

Parameters

\Drupal\Core\Entity\ContentEntityTypeInterface $type: The content entity definition to modify.

Return value

\Drupal\Core\Entity\ContentEntityTypeInterface The modified content entity definition.

1 call to EntityTypeInfo::addModerationToEntity()
EntityTypeInfo::entityTypeAlter in src/EntityTypeInfo.php
Adds Moderation configuration to appropriate entity types.

File

src/EntityTypeInfo.php, line 101

Class

EntityTypeInfo
Service class for manipulating entity type information.

Namespace

Drupal\workbench_moderation

Code

protected function addModerationToEntity(ContentEntityTypeInterface $type) {
  if (!$type
    ->hasHandlerClass('moderation')) {
    $handler_class = !empty($this->moderationHandlers[$type
      ->id()]) ? $this->moderationHandlers[$type
      ->id()] : ModerationHandler::class;
    $type
      ->setHandlerClass('moderation', $handler_class);
  }
  if (!$type
    ->hasLinkTemplate('latest-version') && $type
    ->hasLinkTemplate('canonical')) {
    $type
      ->setLinkTemplate('latest-version', $type
      ->getLinkTemplate('canonical') . '/latest');
  }

  // @todo Core forgot to add a direct way to manipulate route_provider, so
  // we have to do it the sloppy way for now.
  $providers = $type
    ->getRouteProviderClasses() ?: [];
  if (empty($providers['moderation'])) {
    $providers['moderation'] = EntityModerationRouteProvider::class;
    $type
      ->setHandlerClass('route_provider', $providers);
  }
  return $type;
}