本文整理汇总了PHP中Drupal\field\Entity\FieldStorageConfig::loadByName方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldStorageConfig::loadByName方法的具体用法?PHP FieldStorageConfig::loadByName怎么用?PHP FieldStorageConfig::loadByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\field\Entity\FieldStorageConfig
的用法示例。
在下文中一共展示了FieldStorageConfig::loadByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
function setUp()
{
parent::setUp();
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
// Create and login user.
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer languages', 'access administration pages', 'administer content types', 'administer comments', 'create article content', 'access comments', 'post comments', 'skip comment approval'));
$this->drupalLogin($admin_user);
// Add language.
$edit = array('predefined_langcode' => 'fr');
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Set "Article" content type to use multilingual support.
$edit = array('language_configuration[language_show]' => TRUE);
$this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
// Enable content language negotiation UI.
\Drupal::state()->set('language_test.content_language_type', TRUE);
// Set interface language detection to user and content language detection
// to URL. Disable inheritance from interface language to ensure content
// language will fall back to the default language if no URL language can be
// detected.
$edit = array('language_interface[enabled][language-user]' => TRUE, 'language_content[enabled][language-url]' => TRUE, 'language_content[enabled][language-interface]' => FALSE);
$this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
// Change user language preference, this way interface language is always
// French no matter what path prefix the URLs have.
$edit = array('preferred_langcode' => 'fr');
$this->drupalPostForm("user/" . $admin_user->id() . "/edit", $edit, t('Save'));
// Create comment field on article.
$this->container->get('comment.manager')->addDefaultField('node', 'article');
// Make comment body translatable.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
$this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.');
}
示例2: setUp
function setUp()
{
parent::setUp();
$this->drupalLogin($this->drupalCreateUser(['access comments']));
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('es')->save();
// Make the comment body field translatable. The title is already
// translatable by definition.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
// Set up comment titles.
$this->comment_titles = 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->node_user_commented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'cid' => '', 'pid' => '', 'node_type' => '');
$this->comment = entity_create('comment', $comment);
// Add field values and translate the comment.
$this->comment->subject->value = $this->comment_titles['en'];
$this->comment->comment_body->value = $this->comment_titles['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->comment_titles[$langcode];
$translation->subject->value = $this->comment_titles[$langcode];
}
$this->comment->save();
}
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser([
'administer products',
'administer stores',
'access administration pages',
]);
$this->drupalLogin($this->adminUser);
$this->referenceField = FieldStorageConfig::loadByName('commerce_product', 'stores');
$display = EntityFormDisplay::load('commerce_product.default.default');
$display->setComponent('stores', [
'type' => 'entity_select',
'settings' => [
'autocomplete_threshold' => 2,
],
])->save();
$variation = $this->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this->randomMachineName()),
]);
$this->product = $this->createEntity('commerce_product', [
'type' => 'default',
'title' => $this->randomMachineName(),
'variations' => [$variation],
]);
}
示例4: testImport
/**
* Tests that importing list_float fields works.
*/
public function testImport()
{
$field_name = 'field_options_float';
$type = 'options_install_test';
// Test the results on installing options_config_install_test. All the
// necessary configuration for this test is created by installing that
// module.
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
$admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
// Export active config to sync.
$this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
// Set the active to not use dots in the allowed values key names.
$edit = array('settings[allowed_values]' => "0|Zero\n1|One");
$this->drupalPostForm($admin_path, $edit, t('Save field settings'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '1' => 'One'));
// Import configuration with dots in the allowed values key names. This
// tests \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate().
$this->drupalGet('admin/config/development/configuration');
$this->drupalPostForm(NULL, array(), t('Import all'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
// Delete field to test creation. This tests
// \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
FieldConfig::loadByName('node', $type, $field_name)->delete();
$this->drupalGet('admin/config/development/configuration');
$this->drupalPostForm(NULL, array(), t('Import all'));
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
}
示例5: testEntityFormLanguage
/**
* Tests entity form language.
*/
function testEntityFormLanguage()
{
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'administer content types'));
$this->drupalLogin($web_user);
// Create a node with language LanguageInterface::LANGCODE_NOT_SPECIFIED.
$edit = array();
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->drupalGet('node/add/page');
$form_langcode = \Drupal::state()->get('entity_test.form_langcode');
$this->drupalPostForm(NULL, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.');
// Edit the node and test the form language.
$this->drupalGet($this->langcodes[0] . '/node/' . $node->id() . '/edit');
$form_langcode = \Drupal::state()->get('entity_test.form_langcode');
$this->assertTrue($node->language()->getId() == $form_langcode, 'Form language is the same as the entity language.');
// Explicitly set form langcode.
$langcode = $this->langcodes[0];
$form_state_additions['langcode'] = $langcode;
\Drupal::service('entity.form_builder')->getForm($node, 'default', $form_state_additions);
$form_langcode = \Drupal::state()->get('entity_test.form_langcode');
$this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.');
// Enable language selector.
$this->drupalGet('admin/structure/types/manage/page');
$edit = array('language_configuration[language_alterable]' => TRUE, 'language_configuration[langcode]' => LanguageInterface::LANGCODE_NOT_SPECIFIED);
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.');
// Create a node with language.
$edit = array();
$langcode = $this->langcodes[0];
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit['body[0][value]'] = $this->randomMachineName(16);
$edit['langcode[0][value]'] = $langcode;
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$this->assertText(t('Basic page @title has been created.', array('@title' => $edit['title[0][value]'])), 'Basic page created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$this->assert(isset($view_link), 'The message area contains a link to a node');
// Check to make sure the node was created.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertTrue($node, 'Node found in database.');
// Make body translatable.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->setTranslatable(TRUE);
$field_storage->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$this->assertTrue($field_storage->isTranslatable(), 'Field body is translatable.');
// Create a body translation and check the form language.
$langcode2 = $this->langcodes[1];
$translation = $node->addTranslation($langcode2);
$translation->title->value = $this->randomString();
$translation->body->value = $this->randomMachineName(16);
$translation->setOwnerId($web_user->id());
$node->save();
$this->drupalGet($langcode2 . '/node/' . $node->id() . '/edit');
$form_langcode = \Drupal::state()->get('entity_test.form_langcode');
$this->assertTrue($langcode2 == $form_langcode, "Node edit form language is {$langcode2}.");
}
示例6: testTrackerAll
/**
* Tests for the presence of nodes on the global tracker listing.
*/
function testTrackerAll()
{
$this->drupalLogin($this->user);
$unpublished = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'status' => 0));
$published = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'status' => 1));
$this->drupalGet('activity');
$this->assertNoText($unpublished->label(), 'Unpublished node does not show up in the tracker listing.');
$this->assertText($published->label(), 'Published node shows up in the tracker listing.');
$this->assertLink(t('My recent content'), 0, 'User tab shows up on the global tracker page.');
// Assert cache contexts, specifically the pager and node access contexts.
$this->assertCacheContexts(['languages:language_interface', 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions']);
// Assert cache tags for the visible node and node list cache tag.
$this->assertCacheTags(Cache::mergeTags($published->getCacheTags(), $published->getOwner()->getCacheTags(), ['node_list', 'rendered']));
// Delete a node and ensure it no longer appears on the tracker.
$published->delete();
$this->drupalGet('activity');
$this->assertNoText($published->label(), 'Deleted node does not show up in the tracker listing.');
// Test proper display of time on activity page when comments are disabled.
// Disable comments.
FieldStorageConfig::loadByName('node', 'comment')->delete();
$node = $this->drupalCreateNode(['title' => 'testing_node_presave', 'status' => 1]);
$this->drupalGet('activity');
$this->assertText($node->label(), 'Published node shows up in the tracker listing.');
$this->assertText(\Drupal::service('date.formatter')->formatTimeDiffSince($node->getChangedTime()), 'The changed time was displayed on the tracker listing.');
}
示例7: 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();
}
示例8: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
// Create content types.
$this->drupalCreateContentType(['type' => 'page']);
$this->drupalCreateContentType(['type' => 'article']);
// 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();
// Add 9 nodes of the type page.
for ($i = 1; $i <= 9; $i++) {
// Adding a different created time per language to avoid to have exactly
// the same value per nid and langcode.
$created_time_en = new \DateTime('February ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM');
$created_time_es = new \DateTime('March ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM');
$node = $this->drupalCreateNode(array('title' => 'test page' . $i . ' EN', 'body' => 'test page' . $i, 'type' => 'page', 'created' => $created_time_en->format('U'), 'langcode' => 'en'));
// Add Spanish translation to the node.
$node->addTranslation('es', ['title' => 'test page' . $i . ' ES', 'created' => $created_time_es->format('U')]);
$node->save();
}
$created_time = new \DateTime('March 9 2016 11PM');
$this->drupalCreateNode(array('title' => 'test page 10 EN', 'body' => 'test page10', 'type' => 'page', 'created' => $created_time->format('U'), 'langcode' => 'en'));
// Add 10 nodes of the type article.
for ($i = 1; $i <= 10; $i++) {
$created_time = new \DateTime('April ' . $i . ' 2016 ' . str_pad($i, 2, STR_PAD_LEFT, 0) . 'PM');
$this->drupalCreateNode(array('title' => 'test article' . $i . ' EN', 'body' => 'test article' . $i, 'type' => 'article', 'created' => $created_time->format('U'), 'langcode' => 'en'));
}
// Create the users used for the tests.
$this->adminUser = $this->drupalCreateUser(['administer search', 'use advanced search', 'administer facets', 'access administration pages', 'administer nodes', 'access content overview', 'administer content types', 'administer blocks', 'search content', 'administer languages', 'administer site configuration', 'access content']);
}
示例9: 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();
}
示例10: testCalculateDependencies
/**
* Tests the calculateDependencies method.
*/
public function testCalculateDependencies()
{
$comment_type = entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'node'));
$comment_type->save();
$content_type = entity_create('node_type', array('type' => $this->randomMachineName(), 'name' => $this->randomString()));
$content_type->save();
$field_storage = entity_create('field_storage_config', array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'node', 'type' => 'comment'));
$field_storage->save();
entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'settings' => array('comment_type' => $comment_type->id())))->save();
entity_create('field_config', array('field_storage' => FieldStorageConfig::loadByName('node', 'body'), 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_body', 'settings' => array('display_summary' => TRUE)))->save();
$expected = [];
$expected['test_field_get_entity'] = ['module' => ['comment', 'node', 'user']];
// Tests dependencies of relationships.
$expected['test_relationship_dependency'] = ['module' => ['comment', 'node', 'user']];
$expected['test_plugin_dependencies'] = ['module' => ['comment', 'views_test_data'], 'content' => ['RowTest', 'StaticTest', 'StyleTest']];
$expected['test_argument_dependency'] = ['config' => ['core.entity_view_mode.node.teaser', 'field.storage.node.body'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['node', 'search', 'text', 'user']];
foreach ($this::$testViews as $view_id) {
$view = Views::getView($view_id);
$dependencies = $view->calculateDependencies();
$this->assertEqual($expected[$view_id], $dependencies);
$config = $this->config('views.view.' . $view_id);
\Drupal::service('config.storage.staging')->write($view_id, $config->get());
}
// Ensure that dependencies are calculated on the display level.
$expected_display['default'] = ['config' => ['core.entity_view_mode.node.teaser'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['core', 'node', 'search', 'user', 'views']];
$expected_display['page'] = ['config' => ['field.storage.node.body'], 'module' => ['core', 'text', 'views']];
$view = Views::getView('test_argument_dependency');
$view->initDisplay();
foreach ($view->displayHandlers as $display) {
// Calculate the dependencies each display has.
$this->assertEqual($expected_display[$display->getPluginId()], $display->calculateDependencies());
}
}
示例11: 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);
}
示例12: orphans
/**
* Displays links to all products that have not been categorized.
*
* @return
* Renderable form array.
*/
public function orphans()
{
$build = array();
if ($this->config('taxonomy.settings')->get('maintain_index_table')) {
$vid = $this->config('uc_catalog.settings')->get('vocabulary');
$product_types = uc_product_types();
$field = FieldStorageConfig::loadByName('node', 'taxonomy_catalog');
//@todo - figure this out
// $field is a config object, not an array, so this doesn't work.
//$types = array_intersect($product_types, $field['bundles']['node']);
$types = $product_types;
//temporary to get this to work at all
$result = db_query('SELECT DISTINCT n.nid, n.title FROM {node_field_data} n LEFT JOIN (SELECT ti.nid, td.vid FROM {taxonomy_index} ti LEFT JOIN {taxonomy_term_data} td ON ti.tid = td.tid WHERE td.vid = :vid) txnome ON n.nid = txnome.nid WHERE n.type IN (:types[]) AND txnome.vid IS NULL', [':vid' => $vid, ':types[]' => $types]);
$rows = array();
while ($node = $result->fetchObject()) {
$rows[] = $this->l($node->title, Url::fromRoute('entity.node.edit_form', ['node' => $node->nid], ['query' => ['destination' => 'admin/store/products/orphans']]));
}
if (count($rows) > 0) {
$build['orphans'] = array('#theme' => 'item_list', '#items' => $rows);
} else {
$build['orphans'] = array('#markup' => $this->t('All products are currently listed in the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>');
}
} else {
$build['orphans'] = array('#markup' => $this->t('The node terms index is not being maintained, so Ubercart can not determine which products are not entered into the catalog.'), '#prefix' => '<p>', '#suffix' => '</p>');
}
return $build;
}
示例13: setupTestFields
/**
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITest::setupTestFields().
*/
function setupTestFields()
{
parent::setupTestFields();
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$field_storage->translatable = TRUE;
$field_storage->save();
}
示例14: testUserTokens
function testUserTokens()
{
// Add a user picture to the account.
$image = current($this->drupalGetTestFiles('image'));
$edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
$this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
$storage = \Drupal::entityManager()->getStorage('user');
// Load actual user data from database.
$storage->resetCache();
$this->account = $storage->load($this->account->id());
$this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
$picture = ['#theme' => 'user_picture', '#account' => $this->account];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$user_tokens = array('picture' => $renderer->render($picture), 'picture:fid' => $this->account->user_picture->target_id, 'picture:size-raw' => 125, 'ip-address' => NULL, 'roles' => implode(', ', $this->account->getRoles()));
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
// Remove the simpletest-created user role.
$roles = $this->account->getRoles();
$this->account->removeRole(end($roles));
$this->account->save();
// Remove the user picture field and reload the user.
FieldStorageConfig::loadByName('user', 'user_picture')->delete();
$storage->resetCache();
$this->account = $storage->load($this->account->id());
$user_tokens = array('picture' => NULL, 'picture:fid' => NULL, 'ip-address' => NULL, 'roles' => 'authenticated', 'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID);
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
// The ip address token should work for the current user token type.
$tokens = array('ip-address' => \Drupal::request()->getClientIp());
$this->assertTokens('current-user', array(), $tokens);
$anonymous = new AnonymousUserSession();
$tokens = array('roles' => 'anonymous', 'roles:keys' => (string) DRUPAL_ANONYMOUS_RID);
$this->assertTokens('user', array('user' => $anonymous), $tokens);
}
示例15: 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('en' => array('First node en', 'Second node en'), 'es' => array('Primero nodo es', 'Segundo nodo es'), 'fr' => array('Premier nodule fr'));
// Create nodes with translations.
foreach ($this->node_titles['en'] as $index => $title) {
$node = $this->drupalCreateNode(array('title' => $title, 'langcode' => 'en', 'type' => 'page'));
foreach (array('es', '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->randomName(32);
}
}
$node->save();
}
}