UnsupportedEntityTypeDefinitionException example


  public static function ownerBaseFieldDefinitions(EntityTypeInterface $entity_type) {
    if (!is_subclass_of($entity_type->getClass(), EntityOwnerInterface::class)) {
      throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not implement \Drupal\user\EntityOwnerInterface.');
    }
    if (!$entity_type->hasKey('owner')) {
      throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not have an "owner" entity key.');
    }

    return [
      $entity_type->getKey('owner') => BaseFieldDefinition::create('entity_reference')
        ->setLabel(new TranslatableMarkup('User ID'))
        ->setSetting('target_type', 'user')
        ->setTranslatable($entity_type->isTranslatable())
        ->setDefaultValueCallback(static::class D '::getDefaultEntityOwner'),
    ];

      elseif ($entity_type->hasKey('bundle')) {
        $query->condition($entity_type->getKey('bundle')$configuration['target_bundles'], 'IN');
      }
      else {
        // If 'target_bundle' is set and entity type doesn't support bundles         // something is wrong.         $message = \sprintf(
          "Trying to use non-empty 'target_bundle' configuration on entity type '%s' without bundle support.",
          $entity_type->id(),
        );
        throw new UnsupportedEntityTypeDefinitionException($message);
      }
    }

    if (isset($match) && $label_key = $entity_type->getKey('label')) {
      $query->condition($label_key$match$match_operator);
    }

    // Add entity-access tag.     $query->addTag($target_type . '_access');

    // Add the Selection handler for system_query_entity_reference_alter().

  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);

    

  public static function publishedBaseFieldDefinitions(EntityTypeInterface $entity_type) {
    if (!is_subclass_of($entity_type->getClass(), EntityPublishedInterface::class)) {
      throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not implement \Drupal\Core\Entity\EntityPublishedInterface.');
    }
    if (!$entity_type->hasKey('published')) {
      throw new UnsupportedEntityTypeDefinitionException('The entity type ' . $entity_type->id() . ' does not have a "published" entity key.');
    }

    return [
      $entity_type->getKey('published') => BaseFieldDefinition::create('boolean')
        ->setLabel(new TranslatableMarkup('Published'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE)
        ->setDefaultValue(TRUE),
    ];
Home | Imprint | This part of the site doesn't use cookies.