getLastInstalledDefinition example

    $this->addEntityIndex();
    $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
    $expected = [
      'entity_test_update' => [
        t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]),
      ],
    ];
    $this->assertEquals($expected$this->entityDefinitionUpdateManager->getChangeSummary(), 'EntityDefinitionUpdateManager reports the expected change summary.');

    // Run the update and ensure the new index is created.     $entity_type = \Drupal::entityTypeManager()->getDefinition('entity_test_update');
    $original = \Drupal::service('entity.last_installed_schema.repository')->getLastInstalledDefinition('entity_test_update');
    \Drupal::service('entity_type.listener')->onEntityTypeUpdate($entity_type$original);
    $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created.');

    // Remove the index and ensure the update manager reports that as an     // update to the entity type.     $this->removeEntityIndex();
    $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
    $expected = [
      'entity_test_update' => [
        t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]),
      ],
    ];
/** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    return static::getEntityTypeEvents() + static::getFieldStorageDefinitionEvents();
  }

  /** * {@inheritdoc} */
  public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
    if ($this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type->id())) {
      $this->storeDefinitionUpdate(EntityTypeEvents::CREATE);
    }
    $this->storeEvent(EntityTypeEvents::CREATE);

    // Retrieve the live entity type definition in order to warm the static     // cache and then insert the new entity type definition, so we can test that     // the cache doesn't get stale after the event has fired.     if ($this->updateLiveDefinitions) {
      $this->entityTypeManager->getDefinition($entity_type->id());
      $this->state->set('entity_test_rev.entity_type', $entity_type);
    }
  }

  protected function doEntityUpdate($op$entity_type_id) {
    $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. */
$field_storage_definitions = $this->getUpdatedFieldStorageDefinitions(FALSE, TRUE);
    $this->entityDefinitionUpdateManager->updateFieldableEntityType($entity_type$field_storage_definitions);
    $this->assertEntityTypeSchema(FALSE, TRUE);
    $this->insertData(FALSE, TRUE);

    $tables = $schema->findTables('old_%');
    $this->assertCount(4, $tables);
    foreach ($tables as $table) {
      $schema->dropTable($table);
    }

    $original_entity_type = $this->lastInstalledSchemaRepository->getLastInstalledDefinition('entity_test_update');
    $original_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');

    $original_entity_schema_data = $this->installedStorageSchema->get('entity_test_update.entity_schema_data', []);
    $original_field_schema_data = [];
    foreach ($original_storage_definitions as $storage_definition) {
      $original_field_schema_data[$storage_definition->getName()] = $this->installedStorageSchema->get('entity_test_update.field_schema_data.' . $storage_definition->getName()[]);
    }

    // Check that entity type is not revisionable prior to running the update     // process.     $this->assertFalse($entity_type->isRevisionable());

    

      }
    }

    return $summary;
  }

  /** * {@inheritdoc} */
  public function getEntityType($entity_type_id) {
    $entity_type = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);
    return $entity_type ? clone $entity_type : NULL;
  }

  /** * {@inheritdoc} */
  public function getEntityTypes() {
    return $this->entityLastInstalledSchemaRepository->getLastInstalledDefinitions();
  }

  /** * {@inheritdoc} */

  public function getActiveDefinition($entity_type_id) {
    $definition = $this->entityLastInstalledSchemaRepository->getLastInstalledDefinition($entity_type_id);
    return $definition ?: $this->getDefinition($entity_type_id);
  }

  /** * {@inheritdoc} */
  public function clearCachedDefinitions() {
    parent::clearCachedDefinitions();
    $this->handlers = [];
  }

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