function EntityTypeInfo::entityTypeAlter

Implements hook_entity_type_alter().

Adds workspace configuration to appropriate entity types.

Attributes

#[Hook('entity_type_alter')]

File

core/modules/workspaces/src/Hook/EntityTypeInfo.php, line 71

Class

EntityTypeInfo
Defines a class for reacting to entity type information hooks.

Namespace

Drupal\workspaces\Hook

Code

public function entityTypeAlter(array &$entity_types) : void {
  foreach ($entity_types as $entity_type) {
    if (!$this->workspaceInfo
      ->isEntityTypeSupported($entity_type)) {
      continue;
    }
    // Workspace-support status has been declared in the "build" phase, now we
    // can use that information and add additional configuration in the
    // "alter" phase.
    $entity_type->addConstraint('EntityWorkspaceConflict');
    $entity_type->setRevisionMetadataKey('workspace', 'workspace');
    // Non-default workspaces display the active revision on the canonical
    // route of an entity, so the latest version route is no longer needed.
    $link_templates = $entity_type->get('links');
    unset($link_templates['latest-version']);
    $entity_type->set('links', $link_templates);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.