function EntityTypeInfo::entityTypeBuild

Same name in this branch
  1. 11.x core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityTypeBuild()
Same name in other branches
  1. 9 core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityTypeBuild()
  2. 8.9.x core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityTypeBuild()
  3. 10 core/modules/workspaces/src/EntityTypeInfo.php \Drupal\workspaces\EntityTypeInfo::entityTypeBuild()

Implements hook_entity_type_build().

Adds workspace support info to eligible entity types.

File

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

Class

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

Namespace

Drupal\workspaces\Hook

Code

public function entityTypeBuild(array &$entity_types) : void {
    foreach ($entity_types as $entity_type) {
        if ($entity_type->hasHandlerClass('workspace')) {
            continue;
        }
        // Revisionable and publishable entity types are always supported.
        if ($entity_type->entityClassImplements(EntityPublishedInterface::class) && $entity_type->isRevisionable()) {
            $entity_type->setHandlerClass('workspace', DefaultWorkspaceHandler::class);
            // Support for custom blocks has to be determined on a per-entity
            // basis.
            if ($entity_type->id() === 'block_content') {
                $entity_type->setHandlerClass('workspace', BlockContentWorkspaceHandler::class);
            }
        }
        // The 'file' entity type is allowed to perform CRUD operations inside a
        // workspace without being tracked.
        if ($entity_type->id() === 'file') {
            $entity_type->setHandlerClass('workspace', IgnoredWorkspaceHandler::class);
        }
        // Internal entity types are allowed to perform CRUD operations inside a
        // workspace.
        if ($entity_type->isInternal()) {
            $entity_type->setHandlerClass('workspace', IgnoredWorkspaceHandler::class);
        }
    }
}

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