本文整理汇总了PHP中Drupal\language\Entity\ConfigurableLanguage::createFromLangcode方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigurableLanguage::createFromLangcode方法的具体用法?PHP ConfigurableLanguage::createFromLangcode怎么用?PHP ConfigurableLanguage::createFromLangcode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\language\Entity\ConfigurableLanguage
的用法示例。
在下文中一共展示了ConfigurableLanguage::createFromLangcode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$permissions = array('access administration pages', 'administer site configuration');
$this->drupalLogin($this->drupalCreateUser($permissions));
ConfigurableLanguage::createFromLangcode('es')->save();
}
示例2: setUp
protected function setUp()
{
parent::setUp();
// Set up an additional language.
$this->langcodes = array(language_default()->getId(), 'es');
ConfigurableLanguage::createFromLangcode('es')->save();
// Create a content type.
$this->bundle = $this->randomMachineName();
$this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle));
// Enable translation for the current entity type and ensure the change is
// picked up.
content_translation_set_config('node', $this->bundle, 'enabled', TRUE);
drupal_static_reset();
\Drupal::entityManager()->clearCachedBundles();
\Drupal::service('router.builder')->rebuild();
// Add a translatable field to the content type.
entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE))->save();
entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_text', 'bundle' => $this->bundle, 'label' => 'Test text-field'))->save();
entity_get_form_display('node', $this->bundle, 'default')->setComponent('field_test_text', array('type' => 'text_textfield', 'weight' => 0))->save();
// Enable content translation.
$configuration = array('langcode' => language_default()->getId(), 'language_show' => TRUE);
language_save_default_configuration('node', $this->bundle, $configuration);
// Create a translator user.
$permissions = array('access contextual links', 'administer nodes', "edit any {$this->bundle} content", 'translate any entity');
$this->translator = $this->drupalCreateUser($permissions);
}
示例3: setUp
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('entity_test_mulrev');
$this->installEntitySchema('configurable_language');
ConfigurableLanguage::createFromLangcode('es')->save();
}
示例4: setUp
function setUp()
{
parent::setUp();
// Create Page content type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
}
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Make the body field translatable. The title is already translatable by
// definition.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Set up node titles.
$this->node_titles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
// Create node with translations.
$node = $this->drupalCreateNode(array('title' => $this->node_titles['en'], 'langcode' => 'en', 'type' => 'page', 'body' => array(array('value' => $this->node_titles['en']))));
foreach (array('es', 'fr') as $langcode) {
$translation = $node->addTranslation($langcode, array('title' => $this->node_titles[$langcode]));
$translation->body->value = $this->node_titles[$langcode];
}
$node->save();
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
ConfigurableLanguage::createFromLangcode('it')->save();
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
$manager = \Drupal::service('content_translation.manager');
$manager->setEnabled('node', 'article', TRUE);
// Create and log in user.
$web_user = $this->drupalCreateUser(array('view page revisions', 'revert page revisions', 'delete page revisions', 'edit any page content', 'delete any page content', 'translate any entity'));
$this->drupalLogin($web_user);
// Create initial node.
$node = $this->drupalCreateNode();
$settings = get_object_vars($node);
$settings['revision'] = 1;
$settings['isDefaultRevision'] = TRUE;
$nodes = array();
$logs = array();
// Get original node.
$nodes[] = clone $node;
// Create three revisions.
$revision_count = 3;
for ($i = 0; $i < $revision_count; $i++) {
$logs[] = $node->revision_log = $this->randomMachineName(32);
// Create revision with a random title and body and update variables.
$node->title = $this->randomMachineName();
$node->body = array('value' => $this->randomMachineName(32), 'format' => filter_default_format());
$node->setNewRevision();
$node->save();
$node = Node::load($node->id());
// Make sure we get revision information.
$nodes[] = clone $node;
}
$this->nodes = $nodes;
$this->revisionLogs = $logs;
}
示例6: setUp
protected function setUp()
{
parent::setUp();
// Create and log in user.
$test_user = $this->drupalCreateUser(['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.
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up times to be applied to the English and Spanish translations of the
// node create time, so that they are filtered in/out in the
// search_date_query_alter test module.
$created_time_en = new \DateTime('February 10 2016 10PM');
$created_time_es = new \DateTime('March 19 2016 10PM');
$default_format = filter_default_format();
$node = $this->drupalCreateNode(['title' => 'Node EN', 'type' => 'page', 'body' => ['value' => $this->randomMachineName(32), 'format' => $default_format], 'langcode' => 'en', 'created' => $created_time_en->format('U')]);
// Add Spanish translation to the node.
$translation = $node->addTranslation('es', ['title' => 'Node ES']);
$translation->body->value = $this->randomMachineName(32);
$translation->created->value = $created_time_es->format('U');
$node->save();
// Update the index.
$plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
$plugin->updateIndex();
search_update_totals();
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installConfig(['system']);
$this->installConfig(['field']);
$this->installConfig(['text']);
$this->installConfig(['address']);
$this->installEntitySchema('entity_test');
ConfigurableLanguage::createFromLangcode('zh-hant')->save();
// The address module is never installed, so the importer doesn't run
// automatically. Instead, we manually import the address formats we need.
$country_codes = ['AD', 'SV', 'TW', 'US', 'ZZ'];
$importer = \Drupal::service('address.address_format_importer');
$importer->importEntities($country_codes);
$importer->importTranslations(['zh-hant']);
$this->entityType = 'entity_test';
$this->bundle = $this->entityType;
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'address']);
$field_storage->save();
$field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName()]);
$field->save();
$values = ['targetEntityType' => $this->entityType, 'bundle' => $this->bundle, 'mode' => 'default', 'status' => TRUE];
$this->display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->create($values);
$this->display->setComponent($this->fieldName, ['type' => 'address_default', 'settings' => []]);
$this->display->save();
}
示例8: setUp
protected 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.
ConfigurableLanguage::createFromLangcode('es')->save();
// 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->setTranslatable(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->searchableNodes = [];
foreach ($nodes as $setting) {
$this->searchableNodes[] = $this->drupalCreateNode($setting);
}
// Add English translation to the second node.
$translation = $this->searchableNodes[1]->addTranslation('en', array('title' => 'Second node en'));
$translation->body->value = $this->randomMachineName(32);
$this->searchableNodes[1]->save();
// Add Spanish translation to the third node.
$translation = $this->searchableNodes[2]->addTranslation('es', array('title' => 'Third node es'));
$translation->body->value = $this->randomMachineName(32);
$this->searchableNodes[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();
}
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Create Page content type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
}
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Make the body field translatable. The title is already translatable by
// definition.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->translatable = TRUE;
$field_storage->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);
}
示例10: 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.
ConfigurableLanguage::createFromLangcode('es')->save();
// 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 configuration'));
// 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');
}
示例11: testConfigTranslationImport
/**
* Test update changes configuration translations if enabled after language.
*/
public function testConfigTranslationImport()
{
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions'));
$this->drupalLogin($admin_user);
// Add a language. The Afrikaans translation file of locale_test_translate
// (test.af.po) has been prepared with a configuration translation.
ConfigurableLanguage::createFromLangcode('af')->save();
// Enable locale module.
$this->container->get('module_installer')->install(array('locale'));
$this->resetAll();
// Enable import of translations. By default this is disabled for automated
// tests.
$this->config('locale.settings')->set('translation.import_enabled', TRUE)->save();
// Add translation permissions now that the locale module has been enabled.
$edit = array('authenticated[translate interface]' => 'translate interface');
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
// Check and update the translation status. This will import the Afrikaans
// translations of locale_test_translate module.
$this->drupalGet('admin/reports/translations/check');
// Override the Drupal core translation status to be up to date.
// Drupal core should not be a subject in this test.
$status = locale_translation_get_status();
$status['drupal']['af']->type = 'current';
\Drupal::state()->set('locale.translation_status', $status);
$this->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
// Check if configuration translations have been imported.
$override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'system.maintenance');
$this->assertEqual($override->get('message'), 'Ons is tans besig met onderhoud op @site. Wees asseblief geduldig, ons sal binnekort weer terug wees.');
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$moduleHandler = $this->moduleHandler;
$moduleHandler->loadInclude('locale', 'inc', 'locale.translation');
$moduleHandler->loadInclude('locale', 'module');
$language = $input->getArgument('language');
$languages = $this->site->getStandardLanguages();
if (isset($languages[$language])) {
$langcode = $language;
} elseif (array_search($language, $languages)) {
$langcode = array_search($language, $languages);
} else {
$io->error(sprintf($this->trans('commands.locale.language.add.messages.invalid-language'), $language));
return 1;
}
try {
$language = ConfigurableLanguage::createFromLangcode($langcode);
$language->type = LOCALE_TRANSLATION_REMOTE;
$language->save();
$io->info(sprintf($this->trans('commands.locale.language.add.messages.language-add-successfully'), $language->getName()));
} catch (\Exception $e) {
$io->error($e->getMessage());
return 1;
}
return 0;
}
示例13: setUp
function setUp()
{
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['access comments']));
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up comment titles.
$this->commentTitles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
// Create a new comment. Using the one created earlier will not work,
// as it predates the language set-up.
$comment = array('uid' => $this->loggedInUser->id(), 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'cid' => '', 'pid' => '', 'node_type' => '');
$this->comment = Comment::create($comment);
// Add field values and translate the comment.
$this->comment->subject->value = $this->commentTitles['en'];
$this->comment->comment_body->value = $this->commentTitles['en'];
$this->comment->langcode = 'en';
$this->comment->save();
foreach (array('es', 'fr') as $langcode) {
$translation = $this->comment->addTranslation($langcode, array());
$translation->comment_body->value = $this->commentTitles[$langcode];
$translation->subject->value = $this->commentTitles[$langcode];
}
$this->comment->save();
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Enable an additional language.
ConfigurableLanguage::createFromLangcode('de')->save();
$this->installEntitySchema('entity_test_mul');
}
示例15: setUp
public function setUp() {
parent::setup();
$this->installConfig(array('pathauto', 'taxonomy', 'system', 'node'));
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
ConfigurableLanguage::createFromLangcode('fr')->save();
$this->installSchema('node', array('node_access'));
$this->installSchema('system', array('url_alias', 'sequences', 'router'));
$type = NodeType::create(['type' => 'page']);
$type->save();
node_add_body_field($type);
$this->nodePattern = $this->createPattern('node', '/content/[node:title]');
$this->userPattern = $this->createPattern('user', '/users/[user:name]');
\Drupal::service('router.builder')->rebuild();
$this->currentUser = entity_create('user', array('name' => $this->randomMachineName()));
$this->currentUser->save();
}