You are here

class EntityTypeInfo in Workspace 8.2

Same name and namespace in other branches
  1. 8 src/EntityTypeInfo.php \Drupal\workspace\EntityTypeInfo

Manipulates entity type information.

This class contains primarily bridged hooks for compile-time or cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.

@internal

Hierarchy

Expanded class hierarchy of EntityTypeInfo

1 file declares its use of EntityTypeInfo
workspace.module in ./workspace.module
Provides full-site preview functionality for content staging.

File

src/EntityTypeInfo.php, line 17

Namespace

Drupal\workspace
View source
class EntityTypeInfo implements ContainerInjectionInterface {

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The workspace manager service.
   *
   * @var \Drupal\workspace\WorkspaceManagerInterface
   */
  protected $workspaceManager;

  /**
   * Constructs a new EntityTypeInfo instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\workspace\WorkspaceManagerInterface $workspace_manager
   *   The workspace manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, WorkspaceManagerInterface $workspace_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->workspaceManager = $workspace_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('workspace.manager'));
  }

  /**
   * Adds the "EntityWorkspaceConflict" constraint to eligible entity types.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
   *   An associative array of all entity type definitions, keyed by the entity
   *   type name. Passed by reference.
   *
   * @see hook_entity_type_build()
   */
  public function entityTypeBuild(array &$entity_types) {
    foreach ($entity_types as $entity_type) {
      if ($this->workspaceManager
        ->isEntityTypeSupported($entity_type)) {
        $entity_type
          ->addConstraint('EntityWorkspaceConflict');
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityTypeInfo::$entityTypeManager protected property The entity type manager service.
EntityTypeInfo::$workspaceManager protected property The workspace manager service.
EntityTypeInfo::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
EntityTypeInfo::entityTypeBuild public function Adds the "EntityWorkspaceConflict" constraint to eligible entity types.
EntityTypeInfo::__construct public function Constructs a new EntityTypeInfo instance.