onFieldableEntityTypeUpdate example

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 onFieldStorageDefinitionCreate(FieldStorageDefinitionInterface $storage_definition) {
    $this->wrapSchemaException(function D) use ($storage_definition) {
      $this->getStorageSchema()->onFieldStorageDefinitionCreate($storage_definition);
      $this->fieldStorageDefinitions[$storage_definition->getName()] = $storage_definition;
      $this->tableMapping = NULL;
    });
$entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
    switch ($op) {
      case EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED:
        \Drupal::service('entity_type.listener')->onEntityTypeCreate($entity_type);
        break;

      case EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED:
        $original = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledDefinition($entity_type_id);
        $original_field_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledFieldStorageDefinitions($entity_type_id);

        \Drupal::service('entity_type.listener')->onFieldableEntityTypeUpdate($entity_type$original$field_storage_definitions$original_field_storage_definitions);
        break;
    }
  }

  /** * Performs a field storage definition update. * * @param string $op * The operation to perform, possible values are static::DEFINITION_CREATED, * static::DEFINITION_UPDATED or static::DEFINITION_DELETED. * @param array|null $storage_definition * The new field storage definition. * @param array|null $original_storage_definition * The original field storage definition. */
/** * {@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.');
    }

    $original_field_storage_definitions = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type->id());
    $this->entityTypeListener->onFieldableEntityTypeUpdate($entity_type$original$field_storage_definitions$original_field_storage_definitions$sandbox);
    $this->clearCachedDefinitions();
  }

  /** * {@inheritdoc} */
  public function installFieldStorageDefinition($name$entity_type_id$provider, FieldStorageDefinitionInterface $storage_definition) {
    // @todo Pass a mutable field definition interface when we have one. See     // https://www.drupal.org/node/2346329.     if ($storage_definition instanceof BaseFieldDefinition) {
      $storage_definition
        
/** * {@inheritdoc} */
  public function onFieldableEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeInterface $original, array $field_storage_definitions, array $original_field_storage_definitions, array &$sandbox = NULL) {
    $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->onFieldableEntityTypeUpdate($entity_type$original$field_storage_definitions$original_field_storage_definitions$sandbox);
    }

    if ($sandbox === NULL || (isset($sandbox['#finished']) && $sandbox['#finished'] == 1)) {
      $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$original), EntityTypeEvents::UPDATE);
      $this->clearCachedDefinitions();
    }
  }
Home | Imprint | This part of the site doesn't use cookies.