本文整理汇总了PHP中language_save函数的典型用法代码示例。如果您正苦于以下问题:PHP language_save函数的具体用法?PHP language_save怎么用?PHP language_save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了language_save函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Set up an administrative user account and testing keys.
*/
public function setUp()
{
// Call parent::setUp() allowing test cases to pass further modules.
parent::setUp();
$this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer site configuration', 'administer xmlsitemap', 'access content'));
$this->drupalLogin($this->admin_user);
if (!$this->languageManager->getLanguage('fr')) {
// Add a new language.
$language = new Language(array('id' => 'fr', 'name' => 'French'));
language_save($language);
}
if (!$this->languageManager->getLanguage('en')) {
// Add a new language.
$language = new Language(array('id' => 'en', 'name' => 'English'));
language_save($language);
}
// Create the two different language-context sitemaps.
$previous_sitemaps = entity_load_multiple('xmlsitemap');
foreach ($previous_sitemaps as $previous_sitemap) {
$previous_sitemap->delete();
}
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap->context = array('language' => 'en');
xmlsitemap_sitemap_save($sitemap);
$sitemap = $this->entityManager->getStorage('xmlsitemap')->create(array());
$sitemap->context = array('language' => 'fr');
xmlsitemap_sitemap_save($sitemap);
}
示例2: testDefaultTermLanguage
function testDefaultTermLanguage()
{
// Configure the vocabulary to not hide the language selector, and make the
// default language of the terms fixed.
$edit = array('default_language[langcode]' => 'bb', 'default_language[language_show]' => TRUE);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode', 'bb', 'The expected langcode was selected.');
// Make the default language of the terms to be the current interface.
$edit = array('default_language[langcode]' => 'current_interface', 'default_language[language_show]' => TRUE);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode', 'aa', "The expected langcode, 'aa', was selected.");
$this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode', 'bb', "The expected langcode, 'bb', was selected.");
// Change the default language of the site and check if the default terms
// language is still correctly selected.
$old_default = \Drupal::languageManager()->getDefaultLanguage();
$old_default->default = FALSE;
language_save($old_default);
$new_default = \Drupal::languageManager()->getLanguage('cc');
$new_default->default = TRUE;
language_save($new_default);
$edit = array('default_language[langcode]' => 'site_default', 'default_language[language_show]' => TRUE);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode', 'cc', "The expected langcode, 'cc', was selected.");
}
示例3: setUp
/**
* {@inheritdoc}
*/
function setUp()
{
parent::setUp();
// Create Page content type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
}
// Add two new languages.
$language = new Language(array('id' => 'fr', 'name' => 'French'));
language_save($language);
$language = new Language(array('id' => 'es', 'name' => 'Spanish'));
language_save($language);
// Make the body field translatable. The title is already translatable by
// definition.
$field = FieldStorageConfig::loadByName('node', 'body');
$field->translatable = TRUE;
$field->save();
// Set up node titles. They should not include the words "French",
// "English", or "Spanish", as there is a language field in the view
// that prints out those words.
$this->node_titles = array('es' => array('Primero nodo es', 'Segundo nodo es', 'Tercera nodo es'), 'en' => array('First node en', 'Second node en'), 'fr' => array('Premier nœud fr'));
// Create nodes with translations.
foreach ($this->node_titles['es'] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'es', 'type' => 'page', 'promote' => 1));
foreach (array('en', 'fr') as $langcode) {
if (isset($this->node_titles[$langcode][$index])) {
$translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode][$index]));
$translation->body->value = $this->randomMachineName(32);
}
}
$node->save();
}
$user = $this->drupalCreateUser(array('access content overview', 'access content'));
$this->drupalLogin($user);
}
示例4: setUp
function setUp()
{
parent::setUp();
// Create and login user.
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration'));
$this->drupalLogin($test_user);
// Add a new language.
$language = new Language(array('id' => 'es', 'name' => 'Spanish'));
language_save($language);
// Make the body field translatable. The title is already translatable by
// definition. The parent class has already created the article and page
// content types.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Create a few page nodes with multilingual body values.
$default_format = filter_default_format();
$nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'), array('title' => 'Second node this is the Spanish title', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'es'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'));
$this->searchable_nodes = array();
foreach ($nodes as $setting) {
$this->searchable_nodes[] = $this->drupalCreateNode($setting);
}
// Add English translation to the second node.
$translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[1]->save();
// Add Spanish translation to the third node.
$translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es'));
$translation->body->value = $this->randomMachineName(32);
$this->searchable_nodes[2]->save();
// Update the index and then run the shutdown method.
$plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
$plugin->updateIndex();
search_update_totals();
}
示例5: setUp
/**
* {@inheritdoc}
*/
function setUp()
{
parent::setUp();
$this->installSchema('system', array('url_alias', 'router'));
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
$this->installConfig(array('field', 'language'));
// Add English as a language.
$english = new Language(array('id' => 'en', 'name' => 'English'));
language_save($english);
// Add German as a language.
$german = new Language(array('id' => 'de', 'name' => 'Deutsch', 'weight' => -1));
language_save($german);
// Create the test text field.
entity_create('field_storage_config', array('name' => 'field_test_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_text', 'bundle' => 'entity_test', 'translatable' => FALSE))->save();
// Create the test translatable field.
entity_create('field_storage_config', array('name' => 'field_test_translatable_text', 'entity_type' => 'entity_test', 'type' => 'text'))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_translatable_text', 'bundle' => 'entity_test', 'translatable' => TRUE))->save();
// Create the test entity reference field.
entity_create('field_storage_config', array('name' => 'field_test_entity_reference', 'entity_type' => 'entity_test', 'type' => 'entity_reference', 'settings' => array('target_type' => 'entity_test')))->save();
entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_entity_reference', 'bundle' => 'entity_test', 'translatable' => TRUE))->save();
$entity_manager = \Drupal::entityManager();
$link_manager = new LinkManager(new TypeLinkManager(new MemoryBackend('default')), new RelationLinkManager(new MemoryBackend('default'), $entity_manager));
$chain_resolver = new ChainEntityResolver(array(new UuidResolver($entity_manager), new TargetIdResolver()));
// Set up the mock serializer.
$normalizers = array(new ContentEntityNormalizer($link_manager, $entity_manager, \Drupal::moduleHandler()), new EntityReferenceItemNormalizer($link_manager, $chain_resolver), new FieldItemNormalizer(), new FieldNormalizer());
$encoders = array(new JsonEncoder());
$this->serializer = new Serializer($normalizers, $encoders);
}
示例6: testMultilingualSearchFilter
/**
* Tests search with multilingual nodes.
*/
public function testMultilingualSearchFilter()
{
// Create a user with admin for languages, content, and content types, plus
// the ability to access content and searches.
$user = $this->drupalCreateUser(array('administer nodes', 'administer content types', 'administer languages', 'administer content translation', 'access content', 'search content'));
$this->drupalLogin($user);
// Add Spanish language programmatically.
language_save(new Language(array('id' => 'es')));
// Create a content type and make it translatable.
$type = $this->drupalCreateContentType();
$edit = array('language_configuration[language_show]' => TRUE);
$this->drupalPostForm('admin/structure/types/manage/' . $type->type, $edit, t('Save content type'));
$edit = array('entity_types[node]' => TRUE, 'settings[node][' . $type->type . '][translatable]' => TRUE, 'settings[node][' . $type->type . '][fields][title]' => TRUE, 'settings[node][' . $type->type . '][fields][body]' => TRUE);
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save'));
// Add a node in English, with title "sandwich".
$values = array('title' => 'sandwich', 'type' => $type->type);
$node = $this->drupalCreateNode($values);
// "Translate" this node into Spanish, with title "pizza".
$node->addTranslation('es', array('title' => 'pizza', 'status' => NODE_PUBLISHED));
$node->save();
// Run cron so that the search index tables are updated.
$this->cronRun();
// Test the keyword filter by visiting the page.
// The views are in the test view 'test_search', and they just display the
// titles of the nodes in the result, as links.
// Page with a keyword filter of 'pizza'. This should find the Spanish
// translated node, which has 'pizza' in the title, but not the English
// one, which does not have the word 'pizza' in it.
$this->drupalGet('test-filter');
$this->assertLink('pizza', 0, 'Found translation with matching title');
$this->assertNoLink('sandwich', 'Did not find translation with non-matching title');
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$i = 0;
foreach (array('af', 'am', 'ar') as $langcode) {
$language = new Language(array('id' => $langcode, 'weight' => $i--));
language_save($language);
}
}
示例8: testHasTranslation
/**
* Tests hasTranslation().
*/
public function testHasTranslation()
{
$this->installConfig(array('locale_test'));
$locale_config_manager = \Drupal::service('locale.config.typed');
$language = language_save(new Language(array('id' => 'de')));
$result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language);
$this->assertFalse($result, 'There is no translation for locale_test.no_translation configuration.');
$result = $locale_config_manager->hasTranslation('locale_test.translation', $language);
$this->assertTrue($result, 'There is a translation for locale_test.translation configuration.');
}
示例9: testCircularDependency
/**
* Tests hasTranslation().
*/
public function testCircularDependency()
{
// Change the language default object to different values.
$new_language_default = new Language(array('id' => 'fr', 'name' => 'French', 'direction' => LANGUAGE::DIRECTION_LTR, 'weight' => 0, 'method_id' => 'language-default', 'default' => TRUE));
language_save($new_language_default);
$this->drupalLogin($this->root_user);
// Ensure that we can enable early_translation_test on a non-english site.
$this->drupalPostForm('admin/modules', array('modules[Testing][early_translation_test][enable]' => TRUE), t('Save configuration'));
$this->assertResponse(200);
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->installConfig(array('language'));
// Create English and another language beside English.
$language = new Language(array('id' => 'en'));
language_save($language);
$language = new Language(array('id' => 'xx-lolspeak', 'name' => 'Lolspeak'));
language_save($language);
}
示例11: setUp
public function setUp()
{
parent::setUp();
$definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions();
$this->pluginId = key($definitions);
$this->langcode = 'xx';
$language = new Language(array('id' => $this->langcode, 'name' => 'XX'));
language_save($language);
\Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
}
示例12: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Prepare a language object for saving.
$languages = language_list();
$langcode = $form_state['values']['langcode'];
$language = $languages[$langcode];
$language->name = $form_state['values']['name'];
$language->direction = $form_state['values']['direction'];
language_save($language);
$form_state->setRedirect('language.admin_overview');
}
示例13: setUp
protected function setUp()
{
parent::setUp();
$this->installConfig(array('language'));
// Setup English.
language_save(\Drupal::languageManager()->getDefaultLanguage());
// Setup Italian.
$language = new Language(array('id' => 'it', 'name' => 'Italian', 'direction' => Language::DIRECTION_LTR));
language_save($language);
$this->manager = $this->container->get('plugin.manager.condition');
}
示例14: setUp
public function setUp()
{
parent::setUp();
// Create test languages.
$this->langcodes = array(language_load('en'));
for ($i = 1; $i < 3; ++$i) {
$language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString()));
language_save($language);
$this->langcodes[$i] = $language;
}
}
示例15: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
// Prepare a language object for saving.
$languages = language_list();
$langcode = $form_state['values']['langcode'];
$language = $languages[$langcode];
$language->name = $form_state['values']['name'];
$language->direction = $form_state['values']['direction'];
language_save($language);
$form_state['redirect_route']['route_name'] = 'language.admin_overview';
}