getWorkspaceFieldDefinition example

// 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());
  }

  /** * Gets the base field definition for the 'workspace' revision metadata field. * * @return \Drupal\Core\Field\BaseFieldDefinition * The base field definition. */
  protected function getWorkspaceFieldDefinition() {
    return BaseFieldDefinition::create('entity_reference')
      ->setLabel($this->t('Workspace'))
      
Home | Imprint | This part of the site doesn't use cookies.