setEnabled example

$this->installConfig(['content_moderation']);

    $this->moderationInformation = $this->container->get('content_moderation.moderation_information');

    ConfigurableLanguage::createFromLangcode('de')->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
    $workflow->save();

    $this->container->get('content_translation.manager')->setEnabled('entity_test_mulrevpub', 'entity_test_mulrevpub', TRUE);
  }

  /** * @covers ::getDefaultRevisionId */
  public function testGetDefaultRevisionId() {
    $entity_test_rev = EntityTestRev::create([
      'name' => 'Default Revision',
      'moderation_state' => 'published',
    ]);
    $entity_test_rev->save();

    
EntityTestMulBundle::create([
      'id' => 'test',
      'label' => 'Test label',
      'description' => 'My test description',
    ])->save();
  }

  /** * Tests that enabling translation via the API triggers schema updates. */
  public function testPermissions() {
    $this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $this->container->get('content_translation.manager')->setEnabled('entity_test_mul_with_bundle', 'test', TRUE);
    $permissions = $this->container->get('user.permissions')->getPermissions();
    $this->assertEquals(['entity_test']$permissions['translate entity_test_mul']['dependencies']['module']);
    $this->assertEquals(['entity_test.entity_test_mul_bundle.test']$permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);

    // Ensure bundle permission granularity works for bundles not based on     // configuration.     $this->container->get('state')->set('entity_test_mul.permission_granularity', 'bundle');
    $this->container->get('entity_type.manager')->clearCachedDefinitions();
    $permissions = $this->container->get('user.permissions')->getPermissions();
    $this->assertEquals(['entity_test']$permissions['translate entity_test_mul entity_test_mul']['dependencies']['module']);
    
$this->bundleInfo = $this->container->get('entity_type.bundle.info');

    $this->installEntitySchema('entity_test_mul');

    ConfigurableLanguage::createFromLangcode('it')->save();
  }

  /** * Tests that modules can know whether bundles are translatable. */
  public function testHookInvocationOrder() {
    $this->contentTranslationManager->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $this->bundleInfo->clearCachedBundles();
    $this->bundleInfo->getAllBundleInfo();

    // Verify that the test module comes first in the module list, which would     // normally make its hook implementation to be invoked first.     /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
    $module_handler = $this->container->get('module_handler');
    $module_list = $module_handler->getModuleList();
    $expected_modules = [
      'content_translation_test',
      'content_translation',
    ];
// Create some languages.     foreach (['nl', 'es'] as $langcode) {
      ConfigurableLanguage::createFromLangcode($langcode)->save();
    }

    // Create an image media type and article node type.     $this->createMediaType('image', ['id' => 'image']);
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

    // Make the media translatable and ensure the change is picked up.     \Drupal::service('content_translation.manager')->setEnabled('media', 'image', TRUE);

    // Create a media reference field on articles.     $this->createEntityReferenceField(
      'node',
      'article',
      'field_media',
      'Media',
      'media',
      'default',
      ['target_bundles' => ['image']],
      FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
    );
#[Package('system-settings')] trait AdminElasticsearchTestBehaviour
{
    /** * @before */
    public function enableElasticsearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(true);
    }

    /** * @after */
    public function disableElasticsearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(false);
    }

    
$this->entityTypeManager = $this->container->get('entity_type.manager');

    $node_type = $this->entityTypeManager->getStorage('node_type')->create([
      'type' => 'article',
      'label' => 'Article',
    ]);
    $node_type->save();

    /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
    $content_translation_manager = $this->container->get('content_translation.manager');

    $content_translation_manager->setEnabled('node', 'article', TRUE);

    $language = $this->entityTypeManager->getStorage('configurable_language')->create([
      'id' => 'es',
      'label' => 'Spanish',
    ]);
    $language->save();
    // Rebuild the container to setup the language path processors.     $this->rebuildContainer();
  }

  /** * Tests that different translation mechanisms can be used for base fields. */
parent::setUp($import_test_views$modules);

    $node_type = NodeType::create([
      'type' => 'article',
      'label' => 'Article',
    ]);
    $node_type->save();

    /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
    $content_translation_manager = \Drupal::service('content_translation.manager');

    $content_translation_manager->setEnabled('node', 'article', TRUE);

    $language = ConfigurableLanguage::create([
      'id' => 'es',
      'label' => 'Spanish',
    ]);
    $language->save();
    // Rebuild the container to setup the language path processors.     $this->rebuildContainer();
  }

  /** * Tests that different translation mechanisms can be used for base fields. */
protected function setupLanguages() {
    ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save();
    $this->rebuildContainer();
  }

  /** * Enables translations where it needed. */
  protected function enableTranslation() {
    // Enable translation for the current entity type and ensure the change is     // picked up.     \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
    \Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
  }

  /** * Adds term reference field for the article content type. */
  protected function setUpTermReferenceField() {
    $handler_settings = [
      'target_bundles' => [
        $this->vocabulary->id() => $this->vocabulary->id(),
      ],
      
$this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installSchema('book', ['book']);
    $this->installSchema('node', ['node_access']);
    $this->installSchema('system', ['sequences']);
    $this->installConfig(['node', 'book', 'field']);
    $node_type = NodeType::create([
      'type' => $this->randomMachineName(),
      'name' => $this->randomString(),
    ]);
    $node_type->save();
    $this->container->get('content_translation.manager')->setEnabled('node', $node_type->id(), TRUE);
    $book_config = $this->config('book.settings');
    $allowed_types = $book_config->get('allowed_types');
    $allowed_types[] = $node_type->id();
    $book_config->set('allowed_types', $allowed_types)->save();
    // To test every possible combination of root-child / child-child, two     // trees are needed. The first level below the root needs to have two     // leaves and similarly a second level is needed with two-two leaves each:     //     // 1     // / \     // / \

  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('entity_test_mul');
  }

  /** * Tests that enabling translation via the API triggers schema updates. */
  public function testSettingsApi() {
    $this->container->get('content_translation.manager')->setEnabled('entity_test_mul', 'entity_test_mul', TRUE);
    $schema = Database::getConnection()->schema();
    $result =
      $schema->fieldExists('entity_test_mul_property_data', 'content_translation_source') &&
      $schema->fieldExists('entity_test_mul_property_data', 'content_translation_outdated');
    $this->assertTrue($result, 'Schema updates correctly performed.');
  }

}
#[Package('core')] trait ElasticsearchTestTestBehaviour
{
    /** * @before */
    public function enableElasticsearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(true);
    }

    /** * @after */
    public function disableElasticsearch(): void
    {
        $this->getDiContainer()
            ->get(ElasticsearchHelper::class)
            ->setEnabled(false);
    }

    
protected function setUp(): void {
    parent::setUp();

    // Set up an additional language.     ConfigurableLanguage::createFromLangcode('es')->save();

    // Create a content type.     $this->drupalCreateContentType(['type' => 'page']);

    // Enable content translation.     $content_translation_manager = $this->container->get('content_translation.manager');
    $content_translation_manager->setEnabled('node', 'page', TRUE);
    $this->rebuildContainer();

    // Create a translator user.     $permissions = [
      'access contextual links',
      'administer nodes',
      'edit any page content',
      'translate any entity',
    ];
    $this->translator = $this->drupalCreateUser($permissions);
  }

  
if (empty($this->bundle)) {
      $this->bundle = $this->entityTypeId;
    }
  }

  /** * Enables translation for the current entity type and bundle. */
  protected function enableTranslation() {
    // Enable translation for the current entity type and ensure the change is     // picked up.     \Drupal::service('content_translation.manager')->setEnabled($this->entityTypeId, $this->bundle, TRUE);
  }

  /** * Creates the test fields. */
  protected function setupTestFields() {
    if (empty($this->fieldName)) {
      $this->fieldName = 'field_test_et_ui_test';
    }
    FieldStorageConfig::create([
      'field_name' => $this->fieldName,
      
$field_config->save();

    $property_settings = [
      'alt' => 'alt',
      'title' => 'title',
      'file' => 0,
    ];
    $field_config->setThirdPartySetting('content_translation', 'translation_sync', $property_settings);
    $field_config->save();

    $this->contentTranslationManager = $this->container->get('content_translation.manager');
    $this->contentTranslationManager->setEnabled($entity_type_id$entity_type_id, TRUE);

    $this->storage = $this->entityTypeManager->getStorage($entity_type_id);

    foreach ($this->getTestFiles('image') as $file) {
      $entity = File::create((array) $file + ['status' => 1]);
      $entity->save();
    }

    $this->state->set('content_translation.entity_access.file', ['view' => TRUE]);

    $account = User::create([
      
public function setupBundle() {
    parent::setupBundle();
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'article']);
    // Add a comment field to the article content type.     $this->addDefaultCommentField('node', 'article', 'comment_article', CommentItemInterface::OPEN, 'comment_article');
    // Create a page content type.     $this->drupalCreateContentType(['type' => 'page', 'name' => 'page']);
    // Add a comment field to the page content type - this one won't be     // translatable.     $this->addDefaultCommentField('node', 'page', 'comment');
    // Mark this bundle as translatable.     $this->container->get('content_translation.manager')->setEnabled('comment', 'comment_article', TRUE);
  }

  /** * {@inheritdoc} */
  protected function getTranslatorPermissions() {
    return array_merge(parent::getTranslatorPermissions()['post comments', 'administer comments', 'access comments']);
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.