enableEventTracking example

$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 added.');
  }

  /** * Tests entity type and field storage definition events. */
  public function testDefinitionEvents() {
    /** @var \Drupal\entity_test\EntityTestDefinitionSubscriber $event_subscriber */
    $event_subscriber = $this->container->get('entity_test.definition.subscriber');
    $event_subscriber->enableEventTracking();
    $event_subscriber->enableLiveDefinitionUpdates();

    // Test field storage definition events.     $storage_definition = FieldStorageDefinition::create('string')
      ->setName('field_storage_test')
      ->setLabel(new TranslatableMarkup('Field storage test'))
      ->setTargetEntityTypeId('entity_test_rev');

    $this->assertFalse($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::CREATE), 'Entity type create was not dispatched yet.');
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definition);
    $this->assertTrue($event_subscriber->hasEventFired(FieldStorageDefinitionEvents::CREATE), 'Entity type create event successfully dispatched.');
    
Home | Imprint | This part of the site doesn't use cookies.