当前位置: 首页>>代码示例>>PHP>>正文


PHP ConfigurableLanguage::load方法代码示例

本文整理汇总了PHP中Drupal\language\Entity\ConfigurableLanguage::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigurableLanguage::load方法的具体用法?PHP ConfigurableLanguage::load怎么用?PHP ConfigurableLanguage::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\language\Entity\ConfigurableLanguage的用法示例。


在下文中一共展示了ConfigurableLanguage::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPublishedStatusNoFields

 /**
  * Tests changing the published status on a node without fields.
  */
 public function testPublishedStatusNoFields()
 {
     // Test changing the published status of an article without fields.
     $this->drupalLogin($this->administrator);
     // Delete all fields.
     $this->drupalGet('admin/structure/types/manage/article/fields');
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete', array(), t('Delete'));
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_tags/delete', array(), t('Delete'));
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image/delete', array(), t('Delete'));
     // Add a node.
     $default_langcode = $this->langcodes[0];
     $values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
     $entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
     $entity = entity_load($this->entityTypeId, $entity_id, TRUE);
     // Add a content translation.
     $langcode = 'fr';
     $language = ConfigurableLanguage::load($langcode);
     $values[$langcode] = array('title' => array(array('value' => $this->randomMachineName())));
     $entity_type_id = $entity->getEntityTypeId();
     $add_url = Url::fromRoute("entity.{$entity_type_id}.content_translation_add", [$entity->getEntityTypeId() => $entity->id(), 'source' => $default_langcode, 'target' => $langcode], array('language' => $language));
     $this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     $translation = $entity->getTranslation($langcode);
     // Make sure we unpublished the node correctly.
     $this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:29,代码来源:NodeTranslationUITest.php

示例2: testSiteNameTranslation

 /**
  * Tests translating the site name.
  */
 function testSiteNameTranslation()
 {
     $adminUser = $this->drupalCreateUser(array('administer site configuration', 'administer languages'));
     $this->drupalLogin($adminUser);
     // Add a custom language.
     $langcode = 'xx';
     $name = $this->randomMachineName(16);
     $edit = array('predefined_langcode' => 'custom', 'langcode' => $langcode, 'label' => $name, 'direction' => LanguageInterface::DIRECTION_LTR);
     $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
     \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'system.site')->set('name', 'XX site name')->save();
     $this->drupalLogout();
     // The home page in English should not have the override.
     $this->drupalGet('');
     $this->assertNoText('XX site name');
     // During path resolution the system.site configuration object is used to
     // determine the front page. This occurs before language negotiation causing
     // the configuration factory to cache an object without the correct
     // overrides. We are testing that the configuration factory is
     // re-initialised after language negotiation. Ensure that it applies when
     // we access the XX front page.
     // @see \Drupal\Core\PathProcessor::processInbound()
     $this->drupalGet('xx');
     $this->assertText('XX site name');
     // Set the xx language to be the default language and delete the English
     // language so the site is no longer multilingual and confirm configuration
     // overrides still work.
     $language_manager = \Drupal::languageManager()->reset();
     $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
     $this->config('system.site')->set('default_langcode', 'xx')->save();
     ConfigurableLanguage::load('en')->delete();
     $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
     $this->drupalGet('xx');
     $this->assertText('XX site name');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:ConfigLanguageOverrideWebTest.php

示例3: doTestMigration

 /**
  * Helper method to test the migration.
  *
  * @param string $langcode
  *   The langcode of the default language.
  * @param bool $existing
  *   Whether the default language exists on the destination.
  */
 protected function doTestMigration($langcode, $existing = TRUE)
 {
     // The default language of the test fixture is English. Change it to
     // something else before migrating, to be sure that the source site
     // default language is migrated.
     $value = 'O:8:"stdClass":11:{s:8:"language";s:2:"' . $langcode . '";s:4:"name";s:6:"French";s:6:"native";s:6:"French";s:9:"direction";s:1:"0";s:7:"enabled";i:1;s:7:"plurals";s:1:"0";s:7:"formula";s:0:"";s:6:"domain";s:0:"";s:6:"prefix";s:0:"";s:6:"weight";s:1:"0";s:10:"javascript";s:0:"";}';
     $this->sourceDatabase->update('variable')->fields(array('value' => $value))->condition('name', 'language_default')->execute();
     $this->startCollectingMessages();
     $this->executeMigrations(['language', 'default_language']);
     if ($existing) {
         // If the default language exists, we should be able to load it and the
         // default_langcode config should be set.
         $default_language = ConfigurableLanguage::load($langcode);
         $this->assertNotNull($default_language);
         $this->assertSame($langcode, $this->config('system.site')->get('default_langcode'));
     } else {
         // Otherwise, the migration log should contain an error message.
         $messages = $this->migration->getIdMap()->getMessageIterator();
         $count = 0;
         foreach ($messages as $message) {
             $count++;
             $this->assertSame($message->message, "The language '{$langcode}' does not exist on this site.");
             $this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
         }
         $this->assertSame($count, 1);
     }
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:35,代码来源:MigrateDefaultLanguageTrait.php

示例4: assertLanguage

 /**
  * Asserts various properties of a configurable language entity.
  *
  * @param string $id
  *   The language ID.
  * @param string $label
  *   The language name.
  * @param string $direction
  *   (optional) The language's direction (one of the DIRECTION_* constants in
  *   ConfigurableLanguageInterface). Defaults to LTR.
  * @param int $weight
  *   (optional) The weight of the language. Defaults to 0.
  */
 protected function assertLanguage($id, $label, $direction = ConfigurableLanguageInterface::DIRECTION_LTR, $weight = 0)
 {
     /** @var \Drupal\language\ConfigurableLanguageInterface $language */
     $language = ConfigurableLanguage::load($id);
     $this->assertTrue($language instanceof ConfigurableLanguageInterface);
     $this->assertIdentical($label, $language->label());
     $this->assertIdentical($direction, $language->getDirection());
     $this->assertIdentical(0, $language->getWeight());
     $this->assertFalse($language->isLocked());
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:23,代码来源:MigrateLanguageTest.php

示例5: setUp

 protected function setUp()
 {
     parent::setUp();
     // Create test languages.
     $this->langcodes = array(ConfigurableLanguage::load('en'));
     for ($i = 1; $i < 3; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()));
         $language->save();
         $this->langcodes[$i] = $language;
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:BlockLanguageCacheTest.php

示例6: import

 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $destination = $row->getDestination();
     $langcode = $destination['default_langcode'];
     // Check if the language exists.
     if (ConfigurableLanguage::load($langcode) === NULL) {
         throw new MigrateException("The language '{$langcode}' does not exist on this site.");
     }
     $this->config->set('default_langcode', $destination['default_langcode']);
     $this->config->save();
     return [$this->config->getName()];
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:DefaultLangcode.php

示例7: testDependencyInjectedNewDefaultLanguage

 /**
  * Test dependency injected Language object against a new default language
  * object.
  *
  * @see \Drupal\Core\Language\Language
  */
 function testDependencyInjectedNewDefaultLanguage()
 {
     $default_language = ConfigurableLanguage::load(\Drupal::languageManager()->getDefaultLanguage()->getId());
     // Change the language default object to different values.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     $this->config('system.site')->set('default_langcode', 'fr')->save();
     // The language system creates a Language object which contains the
     // same properties as the new default language object.
     $result = \Drupal::languageManager()->getCurrentLanguage();
     $this->assertIdentical($result->getId(), 'fr');
     // Delete the language to check that we fallback to the default.
     try {
         entity_delete_multiple('configurable_language', array('fr'));
         $this->fail('Expected DeleteDefaultLanguageException thrown.');
     } catch (DeleteDefaultLanguageException $e) {
         $this->pass('Expected DeleteDefaultLanguageException thrown.');
     }
     // Re-save the previous default language and the delete should work.
     $this->config('system.site')->set('default_langcode', $default_language->getId())->save();
     entity_delete_multiple('configurable_language', array('fr'));
     $result = \Drupal::languageManager()->getCurrentLanguage();
     $this->assertIdentical($result->getId(), $default_language->getId());
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:29,代码来源:LanguageDependencyInjectionTest.php

示例8: doTestTranslationDeletion

 /**
  * Tests translation deletion.
  */
 protected function doTestTranslationDeletion()
 {
     // Confirm and delete a translation.
     $this->drupalLogin($this->translator);
     $langcode = 'fr';
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     $language = ConfigurableLanguage::load($langcode);
     $url = $entity->urlInfo('edit-form', array('language' => $language));
     $this->drupalPostForm($url, array(), t('Delete translation'));
     $this->drupalPostForm(NULL, array(), t('Delete @language translation', array('@language' => $language->getName())));
     $entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
     if ($this->assertTrue(is_object($entity), 'Entity found')) {
         $translations = $entity->getTranslationLanguages();
         $this->assertTrue(count($translations) == 2 && empty($translations[$langcode]), 'Translation successfully deleted.');
     }
     // Check that the translator cannot delete the original translation.
     $args = [$this->entityTypeId => $entity->id(), 'language' => 'en'];
     $this->drupalGet(Url::fromRoute('content_translation.translation_delete_' . $this->entityTypeId, $args));
     $this->assertResponse(403);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:23,代码来源:ContentTranslationUITestBase.php

示例9: testLanguageConfiguration

 /**
  * Functional tests for adding, editing and deleting languages.
  */
 function testLanguageConfiguration()
 {
     // Ensure the after installing the language module the weight of the English
     // language is still 0.
     $this->assertEqual(ConfigurableLanguage::load('en')->getWeight(), 0, 'The English language has a weight of 0.');
     // User to add and remove language.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
     $this->drupalLogin($admin_user);
     // Check if the Default English language has no path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
     // Check that Add language is a primary button.
     $this->drupalGet('admin/config/regional/language/add');
     $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button');
     // Add predefined language.
     $edit = array('predefined_langcode' => 'fr');
     $this->drupalPostForm(NULL, $edit, 'Add language');
     $this->assertText('French');
     $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
     // Langcode for Languages is always 'en'.
     $language = $this->config('language.entity.fr')->get();
     $this->assertEqual($language['langcode'], 'en');
     // Check if the Default English language has no path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
     // Check if French has a path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');
     // Check if we can change the default language.
     $this->drupalGet('admin/config/regional/language');
     $this->assertFieldChecked('edit-site-default-language-en', 'English is the default language.');
     // Change the default language.
     $edit = array('site_default_language' => 'fr');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->rebuildContainer();
     $this->assertFieldChecked('edit-site-default-language-fr', 'Default language updated.');
     $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE, 'langcode' => 'fr']), [], 'Correct page redirection.');
     // Check if a valid language prefix is added after changing the default
     // language.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
     // Check if French still has a path prefix.
     $this->drupalGet('admin/config/regional/language/detection/url');
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
     // Check that prefix can be changed.
     $edit = array('prefix[fr]' => 'french');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.');
     // Check that the prefix can be removed.
     $edit = array('prefix[fr]' => '');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertNoText(t('The prefix may only be left blank for the selected detection fallback language.'), 'The path prefix can be removed for the default language');
     // Change default negotiation language.
     $this->config('language.negotiation')->set('selected_langcode', 'fr')->save();
     // Check that the prefix of a language that is not the negotiation one
     // cannot be changed to empty string.
     $edit = array('prefix[en]' => '');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertText(t('The prefix may only be left blank for the selected detection fallback language.'));
     //  Check that prefix cannot be changed to contain a slash.
     $edit = array('prefix[en]' => 'foo/bar');
     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
     $this->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
     // Remove English language and add a new Language to check if langcode of
     // Language entity is 'en'.
     $this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
     $this->rebuildContainer();
     $this->assertRaw(t('The %language (%langcode) language has been removed.', array('%language' => 'English', '%langcode' => 'en')));
     // Ensure that French language has a weight of 1 after being created through
     // the UI.
     $french = ConfigurableLanguage::load('fr');
     $this->assertEqual($french->getWeight(), 1, 'The French language has a weight of 1.');
     // Ensure that French language can now have a weight of 0.
     $french->setWeight(0)->save();
     $this->assertEqual($french->getWeight(), 0, 'The French language has a weight of 0.');
     // Ensure that new languages created through the API get a weight of 0.
     $afrikaans = ConfigurableLanguage::createFromLangcode('af');
     $afrikaans->save();
     $this->assertEqual($afrikaans->getWeight(), 0, 'The Afrikaans language has a weight of 0.');
     // Ensure that a new language can be created with any weight.
     $arabic = ConfigurableLanguage::createFromLangcode('ar');
     $arabic->setWeight(4)->save();
     $this->assertEqual($arabic->getWeight(), 4, 'The Arabic language has a weight of 0.');
     $edit = array('predefined_langcode' => 'de');
     $this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
     $language = $this->config('language.entity.de')->get();
     $this->assertEqual($language['langcode'], 'fr');
     // Ensure that German language has a weight of 5 after being created through
     // the UI.
     $french = ConfigurableLanguage::load('de');
     $this->assertEqual($french->getWeight(), 5, 'The German language has a weight of 5.');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:95,代码来源:LanguageConfigurationTest.php

示例10: doTestPublishedStatus

 /**
  * {@inheritdoc}
  */
 protected function doTestPublishedStatus()
 {
     $entity_manager = \Drupal::entityManager();
     $storage = $entity_manager->getStorage($this->entityTypeId);
     $storage->resetCache();
     $entity = $storage->load($this->entityId);
     // Unpublish translations.
     foreach ($this->langcodes as $index => $langcode) {
         if ($index > 0) {
             $edit = array('status' => 0);
             $url = $entity->urlInfo('edit-form', array('language' => ConfigurableLanguage::load($langcode)));
             $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
             $storage->resetCache();
             $entity = $storage->load($this->entityId);
             $this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.');
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:21,代码来源:CommentTranslationUITest.php

示例11: testTranslatedEntityReferenceDisplay

 /**
  * Tests if the translated entity is displayed in an entity reference field.
  */
 public function testTranslatedEntityReferenceDisplay()
 {
     $url = $this->referrerEntity->urlInfo();
     $translation_url = $this->referrerEntity->urlInfo('canonical', ['language' => ConfigurableLanguage::load($this->translateToLangcode)]);
     $this->drupalGet($url);
     $this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
     $this->assertText($this->originalLabel, 'The default label of translated reference is displayed.');
     $this->assertNoText($this->translatedLabel, 'The translated label of translated reference is not displayed.');
     $this->drupalGet($translation_url);
     $this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
     $this->assertNoText($this->originalLabel, 'The default label of translated reference is not displayed.');
     $this->assertText($this->translatedLabel, 'The translated label of translated reference is displayed.');
 }
开发者ID:komejo,项目名称:article-test,代码行数:16,代码来源:EntityReferenceFieldTranslatedReferenceViewTest.php

示例12: updateLockedLanguageWeights

 /**
  * {@inheritdoc}
  */
 public function updateLockedLanguageWeights()
 {
     // Get the weight of the last configurable language.
     $configurable_languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
     $max_weight = end($configurable_languages)->getWeight();
     $locked_languages = $this->getLanguages(LanguageInterface::STATE_LOCKED);
     // Update locked language weights to maintain the existing order, if
     // necessary.
     if (reset($locked_languages)->getWeight() <= $max_weight) {
         foreach ($locked_languages as $language) {
             // Update system languages weight.
             $max_weight++;
             ConfigurableLanguage::load($language->getId())->setWeight($max_weight)->save();
         }
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:19,代码来源:ConfigurableLanguageManager.php

示例13: doTestLanguageFallback

 /**
  * Executes the language fallback test for the given entity type.
  *
  * @param string $entity_type
  *   The entity type to run the tests with.
  */
 protected function doTestLanguageFallback($entity_type)
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
     $this->langcodes[] = $current_langcode;
     $values = array();
     foreach ($this->langcodes as $langcode) {
         $values[$langcode]['name'] = $this->randomMachineName();
         $values[$langcode]['user_id'] = mt_rand(0, 127);
     }
     $default_langcode = $this->langcodes[0];
     $langcode = $this->langcodes[1];
     $langcode2 = $this->langcodes[2];
     $langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
     $languages = $this->languageManager->getLanguages();
     $language = ConfigurableLanguage::load($languages[$langcode]->getId());
     $language->set('weight', 1);
     $language->save();
     $this->languageManager->reset();
     $controller = $this->entityManager->getStorage($entity_type);
     $entity = $controller->create(array($langcode_key => $default_langcode) + $values[$default_langcode]);
     $entity->save();
     $entity->addTranslation($langcode, $values[$langcode]);
     $entity->save();
     // Check that retrieving the current translation works as expected.
     $entity = $this->reloadEntity($entity);
     $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2);
     $this->assertEqual($translation->language()->getId(), $default_langcode, 'The current translation language matches the expected one.');
     // Check that language fallback respects language weight by default.
     $language = ConfigurableLanguage::load($languages[$langcode]->getId());
     $language->set('weight', -1);
     $language->save();
     $translation = $this->entityManager->getTranslationFromContext($entity, $langcode2);
     $this->assertEqual($translation->language()->getId(), $langcode, 'The current translation language matches the expected one.');
     // Check that the current translation is properly returned.
     $translation = $this->entityManager->getTranslationFromContext($entity);
     $this->assertEqual($langcode, $translation->language()->getId(), 'The current translation language matches the topmost language fallback candidate.');
     $entity->addTranslation($current_langcode, $values[$current_langcode]);
     $translation = $this->entityManager->getTranslationFromContext($entity);
     $this->assertEqual($current_langcode, $translation->language()->getId(), 'The current translation language matches the current language.');
     // Check that if the entity has no translation no fallback is applied.
     $entity2 = $controller->create(array($langcode_key => $default_langcode));
     // Get an view builder.
     $controller = $this->entityManager->getViewBuilder($entity_type);
     $entity2_build = $controller->view($entity2);
     $entity2_output = (string) $renderer->renderRoot($entity2_build);
     $translation = $this->entityManager->getTranslationFromContext($entity2, $default_langcode);
     $translation_build = $controller->view($translation);
     $translation_output = (string) $renderer->renderRoot($translation_build);
     $this->assertIdentical($entity2_output, $translation_output, 'When the entity has no translation no fallback is applied.');
     // Checks that entity translations are rendered properly.
     $controller = $this->entityManager->getViewBuilder($entity_type);
     $build = $controller->view($entity);
     $renderer->renderRoot($build);
     $this->assertEqual($build['label']['#markup'], $values[$current_langcode]['name'], 'By default the entity is rendered in the current language.');
     $langcodes = array_combine($this->langcodes, $this->langcodes);
     // We have no translation for the $langcode2 language, hence the expected
     // result is the topmost existing translation, that is $langcode.
     $langcodes[$langcode2] = $langcode;
     foreach ($langcodes as $desired => $expected) {
         $build = $controller->view($entity, 'full', $desired);
         // Unset the #cache key so that a fresh render is produced with each pass,
         // making the renderable array keys available to compare.
         unset($build['#cache']);
         $renderer->renderRoot($build);
         $this->assertEqual($build['label']['#markup'], $values[$expected]['name'], 'The entity is rendered in the expected language.');
     }
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:75,代码来源:EntityTranslationTest.php

示例14: getNativeLanguages

 /**
  * {@inheritdoc}
  */
 public function getNativeLanguages()
 {
     $languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
     $natives = array();
     $original_language = $this->getConfigOverrideLanguage();
     foreach ($languages as $langcode => $language) {
         $this->setConfigOverrideLanguage($language);
         $natives[$langcode] = ConfigurableLanguage::load($langcode);
     }
     $this->setConfigOverrideLanguage($original_language);
     Language::sort($natives);
     return $natives;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:16,代码来源:ConfigurableLanguageManager.php

示例15: testMultilingualMenuNodeFormWidget

 /**
  * Testing correct loading and saving of menu links via node form widget in a multilingual environment.
  */
 function testMultilingualMenuNodeFormWidget()
 {
     // Setup languages.
     $langcodes = array('de');
     foreach ($langcodes as $langcode) {
         ConfigurableLanguage::createFromLangcode($langcode)->save();
     }
     array_unshift($langcodes, \Drupal::languageManager()->getDefaultLanguage()->getId());
     $config = \Drupal::service('config.factory')->getEditable('language.negotiation');
     // Ensure path prefix is used to determine the language.
     $config->set('url.source', 'path_prefix');
     // Ensure that there's a path prefix set for english as well.
     $config->set('url.prefixes.' . $langcodes[0], $langcodes[0]);
     $config->save();
     $this->rebuildContainer();
     $languages = array();
     foreach ($langcodes as $langcode) {
         $languages[$langcode] = ConfigurableLanguage::load($langcode);
     }
     // Use a UI form submission to make the node type and menu link content entity translatable.
     $this->drupalLogout();
     $this->drupalLogin($this->rootUser);
     $edit = array('entity_types[node]' => TRUE, 'entity_types[menu_link_content]' => TRUE, 'settings[node][page][settings][language][language_alterable]' => TRUE, 'settings[node][page][translatable]' => TRUE, 'settings[node][page][fields][title]' => TRUE, 'settings[menu_link_content][menu_link_content][translatable]' => TRUE);
     $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
     // Log out and back in as normal user.
     $this->drupalLogout();
     $this->drupalLogin($this->editor);
     // Create a node.
     $node_title = $this->randomMachineName(8);
     $node = Node::create(['type' => 'page', 'title' => $node_title, 'body' => $this->randomMachineName(16), 'uid' => $this->editor->id(), 'status' => 1, 'langcode' => $langcodes[0]]);
     $node->save();
     // Create translation.
     $translated_node_title = $this->randomMachineName(8);
     $node->addTranslation($langcodes[1], ['title' => $translated_node_title, 'body' => $this->randomMachineName(16), 'status' => 1]);
     $node->save();
     // Edit the node and create a menu link.
     $edit = array('menu[enabled]' => 1, 'menu[title]' => $node_title, 'menu[weight]' => 17);
     $options = array('language' => $languages[$langcodes[0]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
     // Edit the node in a different language and translate the menu link.
     $edit = array('menu[enabled]' => 1, 'menu[title]' => $translated_node_title, 'menu[weight]' => 17);
     $options = array('language' => $languages[$langcodes[1]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
     // Assert that the original link exists in the frontend.
     $this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[0]]));
     $this->assertLink($node_title);
     // Assert that the translated link exists in the frontend.
     $this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[1]]));
     $this->assertLink($translated_node_title);
     // Revisit the edit page in original language, check the loaded menu item title and save.
     $options = array('language' => $languages[$langcodes[0]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalGet($url);
     $this->assertFieldById('edit-menu-title', $node_title);
     $this->drupalPostForm(NULL, [], t('Save') . ' ' . t('(this translation)'));
     // Revisit the edit page of the translation and check the loaded menu item title.
     $options = array('language' => $languages[$langcodes[1]]);
     $url = $node->toUrl('edit-form', $options);
     $this->drupalGet($url);
     $this->assertFieldById('edit-menu-title', $translated_node_title);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:66,代码来源:MenuNodeTest.php


注:本文中的Drupal\language\Entity\ConfigurableLanguage::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。