當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentLanguageSettings::create方法代碼示例

本文整理匯總了PHP中Drupal\language\Entity\ContentLanguageSettings::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentLanguageSettings::create方法的具體用法?PHP ContentLanguageSettings::create怎麽用?PHP ContentLanguageSettings::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\language\Entity\ContentLanguageSettings的用法示例。


在下文中一共展示了ContentLanguageSettings::create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: loadByEntityTypeBundle

 /**
  * Loads a content language config entity based on the entity type and bundle.
  *
  * @param string $entity_type_id
  *   ID of the entity type.
  * @param string $bundle
  *   Bundle name.
  *
  * @return $this
  *   The content language config entity if one exists. Otherwise, returns
  *   default values.
  */
 public static function loadByEntityTypeBundle($entity_type_id, $bundle)
 {
     if ($entity_type_id == NULL || $bundle == NULL) {
         return NULL;
     }
     $config = \Drupal::entityManager()->getStorage('language_content_settings')->load($entity_type_id . '.' . $bundle);
     if ($config == NULL) {
         $config = ContentLanguageSettings::create(['target_entity_type_id' => $entity_type_id, 'target_bundle' => $bundle]);
     }
     return $config;
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:23,代碼來源:ContentLanguageSettings.php

示例2: testDefaultLangcode

 /**
  * Tests that the language_get_default_langcode() returns the correct values.
  */
 public function testDefaultLangcode()
 {
     // Add some custom languages.
     foreach (array('aa', 'bb', 'cc') as $language_code) {
         ConfigurableLanguage::create(array('id' => $language_code, 'label' => $this->randomMachineName()))->save();
     }
     // Fixed language.
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode('bb')->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $this->assertEqual($langcode, 'bb');
     // Current interface.
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode('current_interface')->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     $this->assertEqual($langcode, $language_interface->getId());
     // Site's default.
     $old_default = \Drupal::languageManager()->getDefaultLanguage();
     // Ensure the language entity default value is correct.
     $configurable_language = entity_load('configurable_language', $old_default->getId());
     $this->assertTrue($configurable_language->isDefault(), 'The en language entity is flagged as the default language.');
     $this->config('system.site')->set('langcode', 'cc')->save();
     ContentLanguageSettings::loadByEntityTypeBundle('entity_test', 'custom_bundle')->setLanguageAlterable(TRUE)->setDefaultLangcode(LanguageInterface::LANGCODE_SITE_DEFAULT)->save();
     $langcode = language_get_default_langcode('entity_test', 'custom_bundle');
     $this->assertEqual($langcode, 'cc');
     // Ensure the language entity default value is correct.
     $configurable_language = entity_load('configurable_language', $old_default->getId());
     $this->assertFalse($configurable_language->isDefault(), 'The en language entity is not flagged as the default language.');
     $configurable_language = entity_load('configurable_language', 'cc');
     // Check calling the
     // \Drupal\language\ConfigurableLanguageInterface::isDefault() method
     // directly.
     $this->assertTrue($configurable_language->isDefault(), 'The cc language entity is flagged as the default language.');
     // Check the default value of a language field when authors preferred option
     // is selected.
     // Create first an user and assign a preferred langcode to him.
     $some_user = $this->drupalCreateUser();
     $some_user->preferred_langcode = 'bb';
     $some_user->save();
     $this->drupalLogin($some_user);
     ContentLanguageSettings::create(['target_entity_type_id' => 'entity_test', 'target_bundle' => 'some_bundle'])->setLanguageAlterable(TRUE)->setDefaultLangcode('authors_default')->save();
     $this->drupalGet('language-tests/language_configuration_element_test');
     $this->assertOptionSelected('edit-langcode', 'bb');
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:46,代碼來源:LanguageConfigurationElementTest.php


注:本文中的Drupal\language\Entity\ContentLanguageSettings::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。