Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntitySchemaSubscriber.php

function EntitySchemaSubscriber::addRevisionMetadataField

Adds the 'workspace' revision metadata field to an entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type that has been installed or updated.

2 calls to EntitySchemaSubscriber::addRevisionMetadataField()
EntitySchemaSubscriber::onEntityTypeCreate in core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php
Reacts to the creation of the entity type.
EntitySchemaSubscriber::onEntityTypeUpdate in core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php
Reacts to the update of the entity type.

File

core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php, line 129

Class

EntitySchemaSubscriber
Defines a class for listening to entity schema changes.

Namespace

Drupal\workspaces\EventSubscriber

Code

protected function addRevisionMetadataField(EntityTypeInterface $entity_type) {
    if (!$entity_type->hasRevisionMetadataKey('workspace')) {
        // Bail out if there's an existing field called 'workspace'.
        if ($this->entityDefinitionUpdateManager
            ->getFieldStorageDefinition('workspace', $entity_type->id())) {
            throw new \RuntimeException("An existing 'workspace' field was found for the '{$entity_type->id()}' entity type. Set the 'workspace' revision metadata key to use a different field name and run this update function again.");
        }
        // We are only adding a revision metadata key so we don't need to go
        // through the entity update process.
        $entity_type->setRevisionMetadataKey('workspace', 'workspace');
        $this->entityLastInstalledSchemaRepository
            ->setLastInstalledDefinition($entity_type);
    }
    $this->entityDefinitionUpdateManager
        ->installFieldStorageDefinition($entity_type->getRevisionMetadataKey('workspace'), $entity_type->id(), 'workspaces', $this->getWorkspaceFieldDefinition());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal