isLanguageAlterable example

public function testLanguageCommentSettings() {
    // Confirm there is no message about a missing bundle.     $this->assertEmpty($this->migrateMessages, $this->migrateMessages['error'][0] ?? '');

    // Article and Blog content type have multilingual settings of 'Enabled,     // with Translation'. Assert that comments are translatable and the default     // language is 'current_interface'.     $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_article');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_article', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());
    $third_party_settings = [
      'content_translation' => [
        'enabled' => FALSE,
      ],
    ];
    $this->assertSame($third_party_settings$config->get('third_party_settings'));

    $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_blog');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_blog', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    
$defaultConfig, LanguageInterface::LANGCODE_SITE_DEFAULT],
    ];
  }

  /** * @covers ::setLanguageAlterable * @covers ::isLanguageAlterable * * @dataProvider providerLanguageAlterable */
  public function testLanguageAlterable(ContentLanguageSettings $config$expected) {
    $this->assertSame($expected$config->isLanguageAlterable());
  }

  public function providerLanguageAlterable() {
    $alterableConfig = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      'target_bundle' => 'test_bundle',
    ], 'language_content_settings');
    $alterableConfig->setLanguageAlterable(TRUE);

    $nonAlterableConfig = new ContentLanguageSettings([
      'target_entity_type_id' => 'test_entity_type',
      
$module_language_enabled = \Drupal::moduleHandler()->moduleExists('language');
  $description = t('Node module element');

  foreach (NodeType::loadMultiple() as $bundle) {

    // Add also the 'language' select if Language module is enabled and the     // bundle has multilingual support.     // Visibility of the ordering of the language selector is the same as on the     // node/add form.     if ($module_language_enabled) {
      $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundle->id());
      if ($configuration->isLanguageAlterable()) {
        $extra['node'][$bundle->id()]['form']['language'] = [
          'label' => t('Language'),
          'description' => $description,
          'weight' => 0,
        ];
      }
    }
    $extra['node'][$bundle->id()]['display']['language'] = [
      'label' => t('Language'),
      'description' => $description,
      'weight' => 0,
      
/** * Tests migration of comment content language settings. */
  public function testLanguageCommentSettings() {
    // Article and Employee content type have multilingual settings of 'Enabled,     // with Translation'. Assert that comments are not translatable and the     // default language is 'current_interface'.     $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_article');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_article', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());
    $third_party_settings = [
      'content_translation' => [
        'enabled' => FALSE,
      ],
    ];
    $this->assertSame($third_party_settings$config->get('third_party_settings'));

    $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_employee');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_employee', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    
public function testLanguageCommentSettings() {
    // Confirm there is no message about a missing bundle.     $this->assertEmpty($this->migrateMessages, $this->migrateMessages['error'][0] ?? '');

    // Article and Blog content type have multilingual settings of 'Enabled,     // with Translation'. Assert that comments are translatable and the default     // language is 'current_interface'.     $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_article');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_article', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());
    $third_party_settings = [
      'content_translation' => [
        'enabled' => FALSE,
      ],
    ];
    $this->assertSame($third_party_settings$config->get('third_party_settings'));

    $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_blog');
    $this->assertSame('comment', $config->getTargetEntityTypeId());
    $this->assertSame('comment_node_blog', $config->getTargetBundle());
    $this->assertSame('current_interface', $config->getDefaultLangcode());
    


  /** * Tests migration of menu translation ability. */
  public function testLanguageMenuContent() {
    $config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());

    // Test that menus are not alterable when the i18nmenu is not enabled.     $this->sourceDatabase->update('system')
      ->fields(['status' => 0])
      ->condition('name', 'i18nmenu')
      ->execute();

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->getMigration('d6_language_content_menu_settings');
    // Indicate we're rerunning a migration that's already run.     $migration->getIdMap()->prepareUpdate();
    
// Assert that a translatable content is still translatable.     $config = $this->config('language.content_settings.node.blog');
    $this->assertSame($config->get('target_entity_type_id'), 'node');
    $this->assertSame($config->get('target_bundle'), 'blog');
    $this->assertSame($config->get('default_langcode'), 'current_interface');
    $this->assertFalse($config->get('language_alterable'));
    $this->assertTrue($config->get('third_party_settings.content_translation.enabled'));

    // Assert that a translatable content is translatable.     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
    $this->assertFalse($config->isDefaultConfiguration());
    $this->assertTrue($config->isLanguageAlterable());
    $this->assertSame($config->getDefaultLangcode(), 'current_interface');

    // Assert that a non-translatable content is not translatable.     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'forum');
    $this->assertTrue($config->isDefaultConfiguration());
    $this->assertFalse($config->isLanguageAlterable());
    $this->assertSame($config->getDefaultLangcode(), 'site_default');

    // Make sure there's no migration exceptions.     $messages = $this->migration->getIdMap()->getMessages()->fetchAll();
    $this->assertEmpty($messages);

    

  public function testLanguageConfigurationElement() {
    $this->drupalGet('language-tests/language_configuration_element');
    $edit['lang_configuration[langcode]'] = 'current_interface';
    $edit['lang_configuration[language_alterable]'] = FALSE;
    $this->submitForm($edit, 'Save');
    $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');

    // Check that the settings have been saved.     $this->assertEquals('current_interface', $lang_conf->getDefaultLangcode());
    $this->assertFalse($lang_conf->isLanguageAlterable());
    $this->drupalGet('language-tests/language_configuration_element');
    $this->assertTrue($this->assertSession()->optionExists('edit-lang-configuration-langcode', 'current_interface')->isSelected());
    $this->assertSession()->checkboxNotChecked('edit-lang-configuration-language-alterable');

    // Reload the page and save again.     $this->drupalGet('language-tests/language_configuration_element');
    $edit['lang_configuration[langcode]'] = 'authors_default';
    $edit['lang_configuration[language_alterable]'] = TRUE;
    $this->submitForm($edit, 'Save');
    $lang_conf = ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'some_bundle');

    

    $this->assertSettings('entity_test_mul', 'entity_test_mul', TRUE, $edit);
    $field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name');
    $this->assertTrue($field_override->isTranslatable(), 'Base fields can be overridden with a base field bundle override entity.');
    $definitions = $entity_field_manager->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
    $this->assertTrue($definitions['name']->isTranslatable());
    $this->assertFalse($definitions['user_id']->isTranslatable());

    // Test that language settings are correctly stored.     $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_article');
    $this->assertEquals('current_interface', $language_configuration->getDefaultLangcode(), 'The default language for article comments is set to the interface text language selected for page.');
    $this->assertTrue($language_configuration->isLanguageAlterable(), 'The language selector for article comments is shown.');

    // Verify language widget appears on comment type form.     $this->drupalGet('admin/structure/comment/manage/comment_article');
    $this->assertSession()->fieldExists('language_configuration[content_translation]');
    $this->assertSession()->checkboxChecked('edit-language-configuration-content-translation');

    // Verify that translation may be enabled for the article content type.     $edit = [
      'language_configuration[content_translation]' => TRUE,
    ];
    // Make sure the checkbox is available and not checked by default.
$vid = $edit['vid'];
    $this->drupalGet('admin/structure/taxonomy/add');
    $this->submitForm($edit, 'Save');

    // Check that the vocabulary was actually created.     $this->drupalGet('admin/structure/taxonomy/manage/' . $edit['vid']);
    $this->assertSession()->statusCodeEquals(200);

    // Check that the language settings were saved.     $language_settings = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $edit['vid']);
    $this->assertEquals('bb', $language_settings->getDefaultLangcode(), 'The langcode was saved.');
    $this->assertTrue($language_settings->isLanguageAlterable(), 'The visibility setting was saved.');

    // Check that the correct options are selected in the interface.     $this->assertTrue($this->assertSession()->optionExists('edit-default-language-langcode', 'bb')->isSelected());
    $this->assertSession()->checkboxChecked('edit-default-language-language-alterable');

    // Edit the vocabulary and check that the new settings are updated.     $edit = [
      'default_language[langcode]' => 'aa',
      'default_language[language_alterable]' => FALSE,
    ];
    $this->drupalGet('admin/structure/taxonomy/manage/' . $vid);
    

  public function assertLanguageContentSettings(string $target_entity, string $bundle, string $default_langcode, bool $language_alterable, array $third_party_settings): void {
    $config = ContentLanguageSettings::load($target_entity . '.' . $bundle);
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame($target_entity$config->getTargetEntityTypeId());
    $this->assertSame($bundle$config->getTargetBundle());
    $this->assertSame($default_langcode$config->getDefaultLangcode());
    $this->assertSame($language_alterable$config->isLanguageAlterable());
    $this->assertSame($third_party_settings$config->getThirdPartySettings('content_translation'));
  }

}
$element['langcode'] = [
      '#type' => 'select',
      '#title' => t('Default language'),
      '#options' => $options + static::getDefaultOptions(),
      '#description' => t('Explanation of the language options is found on the <a href=":languages_list_page">languages list page</a>.', [':languages_list_page' => Url::fromRoute('entity.configurable_language.collection')->toString()]),
      '#default_value' => ($default_config != NULL) ? $default_config->getDefaultLangcode() : LanguageInterface::LANGCODE_SITE_DEFAULT,
    ];

    $element['language_alterable'] = [
      '#type' => 'checkbox',
      '#title' => t('Show language selector on create and edit pages'),
      '#default_value' => ($default_config != NULL) ? $default_config->isLanguageAlterable() : FALSE,
    ];

    // Add the entity type and bundle information to the form if they are set.     // They will be used, in the submit handler, to generate the names of the     // configuration entities that will store the settings and are a way to uniquely     // identify the entity.     $language = $form_state->get('language') ?: [];
    $language += [
      $element['#name'] => [
        'entity_type' => $element['#entity_information']['entity_type'],
        'bundle' => $element['#entity_information']['bundle'],
      ],


  /** * Tests migration of menu translation ability. */
  public function testLanguageContentMenu() {
    $config = ContentLanguageSettings::load('menu_link_content.menu_link_content');
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame('menu_link_content', $config->getTargetEntityTypeId());
    $this->assertSame('menu_link_content', $config->getTargetBundle());
    $this->assertSame(LanguageInterface::LANGCODE_SITE_DEFAULT, $config->getDefaultLangcode());
    $this->assertTrue($config->isLanguageAlterable());
    $settings = [
      'enabled' => TRUE,
      'bundle_settings' => [
        'untranslatable_fields_hide' => '0',
      ],
    ];
    $this->assertSame($settings$config->getThirdPartySettings('content_translation'));
  }

}

  public function assertLanguageContentSettings(string $target_entity, string $bundle, string $default_langcode, bool $language_alterable, array $third_party_settings): void {
    $config = ContentLanguageSettings::load($target_entity . "." . $bundle);
    $this->assertInstanceOf(ContentLanguageSettings::class$config);
    $this->assertSame($target_entity$config->getTargetEntityTypeId());
    $this->assertSame($bundle$config->getTargetBundle());
    $this->assertSame($default_langcode$config->getDefaultLangcode());
    $this->assertSame($language_alterable$config->isLanguageAlterable());
    $this->assertSame($third_party_settings$config->getThirdPartySettings('content_translation'));
  }

}
public function testLanguageContent() {
    // Assert that a translatable content is still translatable.     $config = $this->config('language.content_settings.node.article');
    $this->assertSame($config->get('target_entity_type_id'), 'node');
    $this->assertSame($config->get('target_bundle'), 'article');
    $this->assertSame($config->get('default_langcode'), 'current_interface');
    $this->assertTrue($config->get('third_party_settings.content_translation.enabled'));

    // Assert that a non-translatable content is not translatable.     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'company');
    $this->assertTrue($config->isDefaultConfiguration());
    $this->assertFalse($config->isLanguageAlterable());
    $this->assertSame($config->getDefaultLangcode(), 'site_default');

    // Assert that a we can assign a language when there is no language lock.     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'employee');
    $this->assertSame($config->getDefaultLangcode(), 'current_interface');
    $this->assertTrue($config->isLanguageAlterable());
  }

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