You are here

protected function EntityTypeInfo::addModerationToEntityType in Workbench Moderation 8.2

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

Modifies an entity type definition to include moderation configuration support.

That "configuration support" includes a configuration form, a hypermedia link, and a route provider to tie it all together. There's also a moderation handler for per-entity-type variation.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityTypeInterface $type: The config entity definition to modify.

Return value

\Drupal\Core\Config\Entity\ConfigEntityTypeInterface The modified config entity definition.

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

File

src/EntityTypeInfo.php, line 135

Class

EntityTypeInfo
Service class for manipulating entity type information.

Namespace

Drupal\workbench_moderation

Code

protected function addModerationToEntityType(ConfigEntityTypeInterface $type) {
  if ($type
    ->hasLinkTemplate('edit-form') && !$type
    ->hasLinkTemplate('moderation-form')) {
    $type
      ->setLinkTemplate('moderation-form', $type
      ->getLinkTemplate('edit-form') . '/moderation');
  }
  if (!$type
    ->getFormClass('moderation')) {
    $type
      ->setFormClass('moderation', BundleModerationConfigurationForm::class);
  }

  // @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'] = EntityTypeModerationRouteProvider::class;
    $type
      ->setHandlerClass('route_provider', $providers);
  }
  return $type;
}