You are here

protected function EntityTypeInfo::addModerationToEntityType in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/EntityTypeInfo.php \Drupal\content_moderation\EntityTypeInfo::addModerationToEntityType()

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::addModerationToEntityType()
EntityTypeInfo::entityTypeAlter in core/modules/content_moderation/src/EntityTypeInfo.php
Adds Moderation configuration to appropriate entity types.

File

core/modules/content_moderation/src/EntityTypeInfo.php, line 167

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\content_moderation

Code

protected function addModerationToEntityType(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');
  }
  $providers = $type
    ->getRouteProviderClasses() ?: [];
  if (empty($providers['moderation'])) {
    $providers['moderation'] = EntityModerationRouteProvider::class;
    $type
      ->setHandlerClass('route_provider', $providers);
  }
  return $type;
}