onFieldableEntityTypeCreate example

/** * {@inheritdoc} */
  public function requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original) {
    return !$this->storage->countFieldData($original, TRUE);
  }

  /** * {@inheritdoc} */
  public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
    $this->onFieldableEntityTypeCreate($entity_type$this->entityFieldManager->getFieldStorageDefinitions($entity_type->id()));
  }

  /** * {@inheritdoc} */
  public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    $this->checkEntityType($entity_type);
    $this->checkEntityType($original);

    // If no schema changes are needed, we don't need to do anything.     if (!$this->requiresEntityStorageSchemaChanges($entity_type$original)) {
      
public function installFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions) {
    $this->clearCachedDefinitions();
    foreach ($field_storage_definitions as $name => $field_storage_definition) {
      if ($field_storage_definition instanceof BaseFieldDefinition) {
        $field_storage_definition
          ->setName($name)
          ->setTargetEntityTypeId($entity_type->id())
          ->setProvider($entity_type->getProvider())
          ->setTargetBundle(NULL);
      }
    }
    $this->entityTypeListener->onFieldableEntityTypeCreate($entity_type$field_storage_definitions);
  }

  /** * {@inheritdoc} */
  public function updateFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions, array &$sandbox = NULL) {
    $original = $this->getEntityType($entity_type->id());

    if ($this->requiresEntityDataMigration($entity_type$original) && $sandbox === NULL) {
      throw new \InvalidArgumentException('The entity schema update for the ' . $entity_type->id() . ' entity type requires a data migration.');
    }

    
public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
    $this->wrapSchemaException(function D) use ($entity_type) {
      $this->getStorageSchema()->onEntityTypeDelete($entity_type);
    });
  }

  /** * {@inheritdoc} */
  public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
    $this->wrapSchemaException(function D) use ($entity_type$field_storage_definitions) {
      $this->getStorageSchema()->onFieldableEntityTypeCreate($entity_type$field_storage_definitions);
    });
  }

  /** * {@inheritdoc} */
  public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array &$sandbox = NULL) {
    $this->wrapSchemaException(function D) use ($entity_type$original$field_storage_definitions$original_field_storage_definitions, &$sandbox) {
      $this->getStorageSchema()->onFieldableEntityTypeUpdate($entity_type$original$field_storage_definitions$original_field_storage_definitions$sandbox);
    });
  }

  
/** * {@inheritdoc} */
  public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
    $entity_type_id = $entity_type->id();

    // @todo Forward this to all interested handlers, not only storage, once     // iterating handlers is possible: https://www.drupal.org/node/2332857.     $storage = $this->entityTypeManager->createHandlerInstance($entity_type->getStorageClass()$entity_type);
    if ($storage instanceof EntityTypeListenerInterface) {
      $storage->onFieldableEntityTypeCreate($entity_type$field_storage_definitions);
    }

    $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id$field_storage_definitions);
    }

    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
    $this->clearCachedDefinitions();
  }

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