当前位置: 首页>>代码示例>>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;未经允许,请勿转载。