hasRevisionMetadataKey example


  public static function revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type) {

    if (!($entity_type instanceof ContentEntityTypeInterface)) {
      throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' is not a content entity type.');
    }
    foreach (['revision_created', 'revision_user', 'revision_log_message'] as $revision_metadata_key) {
      if (!$entity_type->hasRevisionMetadataKey($revision_metadata_key)) {
        throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not have an "' . $revision_metadata_key . '" entity revision metadata key.');
      }
    }

    $fields[$entity_type->getRevisionMetadataKey('revision_created')] = BaseFieldDefinition::create('created')
      ->setLabel(t('Revision create time'))
      ->setDescription(t('The time that the current revision was created.'))
      ->setRevisionable(TRUE);

    $fields[$entity_type->getRevisionMetadataKey('revision_user')] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Revision user'))
      
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
    // Nothing to do here.   }

  /** * Adds the 'workspace' revision metadata field to an entity type. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type that has been installed or updated. */
  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);
    }

    
Home | Imprint | This part of the site doesn't use cookies.