getHooksInfo example

$default_langcode = $this->langcodes[0];
    $langcode = $this->langcodes[1];
    $langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode');
    $default_langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('default_langcode');

    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->entityTypeManager
      ->getStorage($entity_type)
      ->create(['name' => $this->randomMachineName()$langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED]);

    $entity->save();
    $hooks = $this->getHooksInfo();
    $this->assertEmpty($hooks, 'No entity translation hooks are fired when creating an entity.');

    // Verify that we obtain the entity object itself when we attempt to     // retrieve a translation referring to it.     $translation = $entity->getTranslation(LanguageInterface::LANGCODE_NOT_SPECIFIED);
    $this->assertFalse($translation->isNewTranslation(), 'Existing translations are not marked as new.');
    $this->assertSame($entity$translation, 'The translation object corresponding to a non-default language is the entity object itself when the entity is language-neutral.');
    $entity->{$langcode_key}->value = $default_langcode;
    $translation = $entity->getTranslation($default_langcode);
    $this->assertSame($entity$translation, 'The translation object corresponding to the default language (explicit) is the entity object itself.');
    $translation = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT);
    
Home | Imprint | This part of the site doesn't use cookies.