本文整理汇总了PHP中Drupal\user\UserInterface::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::save方法的具体用法?PHP UserInterface::save怎么用?PHP UserInterface::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\user\UserInterface
的用法示例。
在下文中一共展示了UserInterface::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installSchema('system', 'sequences');
$this->installEntitySchema('user');
$this->manager = $this->container->get('plugin.manager.condition');
// Set up the authenticated and anonymous roles.
Role::create(array('id' => RoleInterface::ANONYMOUS_ID, 'label' => 'Anonymous user'))->save();
Role::create(array('id' => RoleInterface::AUTHENTICATED_ID, 'label' => 'Authenticated user'))->save();
// Create new role.
$rid = strtolower($this->randomMachineName(8));
$label = $this->randomString(8);
$role = Role::create(array('id' => $rid, 'label' => $label));
$role->save();
$this->role = $role;
// Setup an anonymous user for our tests.
$this->anonymous = User::create(array('name' => '', 'uid' => 0));
$this->anonymous->save();
// Loading the anonymous user adds the correct role.
$this->anonymous = User::load($this->anonymous->id());
// Setup an authenticated user for our tests.
$this->authenticated = User::create(array('name' => $this->randomMachineName()));
$this->authenticated->save();
// Add the custom role.
$this->authenticated->addRole($this->role->id());
}
示例2: testProfileTabs
/**
* Tests tabs in profile UI.
*/
public function testProfileTabs()
{
$types_data = ['profile_type_0' => ['label' => $this->randomMachineName()], 'profile_type_1' => ['label' => $this->randomMachineName()]];
/** @var ProfileType[] $types */
$types = [];
foreach ($types_data as $id => $values) {
$types[$id] = ProfileType::create(['id' => $id] + $values);
$types[$id]->save();
}
$this->container->get('router.builder')->rebuild();
$this->user1 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user1->save();
$this->user2 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user2->save();
// Create new profiles.
$profile1 = Profile::create($expected = ['type' => $types['profile_type_0']->id(), 'uid' => $this->user1->id()]);
$profile1->save();
$profile2 = Profile::create($expected = ['type' => $types['profile_type_1']->id(), 'uid' => $this->user2->id()]);
$profile2->save();
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config');
$this->clickLink('User profiles');
$this->assertResponse(200);
$this->assertUrl('admin/config/people/profiles');
$this->assertLink($profile1->label());
$this->assertLinkByHref($profile2->toUrl('canonical')->toString());
$tasks = [['entity.profile.collection', []], ['entity.profile_type.collection', []]];
$this->assertLocalTasks($tasks, 0);
}
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE)
{
parent::setUp($import_test_views);
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
// Create the anonymous role.
$this->installConfig(['user']);
// Create an anonymous user.
$storage = \Drupal::entityManager()->getStorage('user');
// Insert a row for the anonymous user.
$storage->create(array('uid' => 0, 'name' => '', 'status' => 0))->save();
$admin_role = Role::create(['id' => 'admin', 'permissions' => ['administer comments', 'access user profiles']]);
$admin_role->save();
/* @var \Drupal\user\RoleInterface $anonymous_role */
$anonymous_role = Role::load(Role::ANONYMOUS_ID);
$anonymous_role->grantPermission('access comments');
$anonymous_role->save();
$this->adminUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$admin_role->id()]]);
$this->adminUser->save();
// Create some comments.
$comment = Comment::create(['subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'status' => 1]);
$comment->save();
$comment_anonymous = Comment::create(['subject' => 'Anonymous comment title', 'uid' => 0, 'name' => 'barry', 'mail' => 'test@example.com', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1]);
$comment_anonymous->save();
}
示例4: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['access user profiles', 'administer profiles', 'administer profile types', 'bypass profile access', 'access administration pages']);
$this->user1 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user1->save();
$this->user2 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user2->save();
}
示例5: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('user');
$this->installSchema('system', 'sequences');
$devel_role = Role::create(['id' => 'admin', 'permissions' => ['access devel information']]);
$devel_role->save();
$this->develUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$devel_role->id()]]);
$this->develUser->save();
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('file');
$this->installSchema('file', 'file_usage');
$this->installSchema('system', 'sequences');
$this->user = User::create(['name' => 'username', 'status' => 1]);
$this->user->save();
}
示例7: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
// Add a field to both entities.
$this->addField('string', 'field_shared', 'user');
$this->addField('string', 'field_shared', 'simplenews_subscriber');
// Create a user.
$this->user = $this->drupalCreateUser(array('administer simplenews subscriptions', 'administer simplenews settings'));
$this->user->setEmail('user@example.com');
$this->user->set('field_shared', $this->randomMachineName());
$this->user->save();
}
示例8: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test_enhanced');
$this->installSchema('system', ['key_value_expire', 'sequences']);
$bundle = EnhancedEntityBundle::create(['id' => 'default', 'label' => 'Default']);
$bundle->save();
$this->user = User::create(['name' => 'username', 'status' => 1]);
$this->user->save();
\Drupal::service('current_user')->setAccount($this->user);
}
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installEntitySchema('file');
$this->installEntitySchema('user');
$this->installSchema('file', array('file_usage'));
$this->installSchema('system', 'sequences');
$this->user1 = User::create(['name' => 'user1', 'status' => 1]);
$this->user1->save();
$this->user2 = User::create(['name' => 'user2', 'status' => 1]);
$this->user2->save();
$this->file = File::create(array('uid' => $this->user1->id(), 'filename' => 'druplicon.txt', 'filemime' => 'text/plain'));
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE)
{
parent::setUp($import_test_views);
$this->installEntitySchema('user');
$role_with_access = Role::create(['id' => 'with_access', 'permissions' => ['view test entity field']]);
$role_with_access->save();
$role_without_access = Role::create(['id' => 'without_access', 'permissions' => []]);
$role_without_access->save();
$this->userWithAccess = User::create(['name' => $this->randomMachineName(), 'roles' => [$role_with_access->id()]]);
$this->userWithAccess->save();
$this->userWithoutAccess = User::create(['name' => $this->randomMachineName(), 'roles' => [$role_without_access->id()]]);
$this->userWithoutAccess->save();
}
示例11: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->enableViewsTestModule();
$this->webUser = $this->drupalCreateUser();
$roles = $this->webUser->getRoles();
$this->webRole = $roles[0];
$this->normalRole = $this->drupalCreateRole(array());
$this->normalUser = $this->drupalCreateUser(array('views_test_data test permission'));
$this->normalUser->addRole($this->normalRole);
$this->normalUser->save();
// @todo when all the plugin information is cached make a reset function and
// call it here.
}
示例12: setUp
/**
* Sets up the test.
*/
protected function setUp()
{
parent::setUp();
$this->installSchema('system', ['sequences', 'key_value_expire']);
$this->installEntitySchema('user');
\Drupal::service('router.builder')->rebuild();
/** @var \Drupal\user\RoleInterface $role */
$role = Role::create(array('id' => 'admin', 'label' => 'admin'));
$role->grantPermission('link to any page');
$role->save();
$this->testUser = User::create(array('name' => 'foobar', 'mail' => 'foobar@example.com'));
$this->testUser->addRole($role->id());
$this->testUser->save();
\Drupal::service('current_user')->setAccount($this->testUser);
}
示例13: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->installSchema('system', ['key_value_expire']);
\Drupal::service('router.builder')->rebuild();
$this->testUser = User::create(array('name' => 'foobar1', 'mail' => 'foobar1@example.com'));
$this->testUser->save();
\Drupal::service('current_user')->setAccount($this->testUser);
$this->testAutocreateUser = User::create(array('name' => 'foobar2', 'mail' => 'foobar2@example.com'));
$this->testAutocreateUser->save();
for ($i = 1; $i < 3; $i++) {
$entity = EntityTest::create(array('name' => $this->randomMachineName()));
$entity->save();
$this->referencedEntities[] = $entity;
}
}
示例14: testCRUDUI
/**
* Tests CRUD operations for profile types through the UI.
*/
public function testCRUDUI()
{
$types_data = ['profile_type_0' => ['label' => $this->randomMachineName()], 'profile_type_1' => ['label' => $this->randomMachineName()]];
/** @var ProfileType[] $types */
$types = [];
foreach ($types_data as $id => $values) {
$types[$id] = $this->createProfileType($id, $values['label']);
}
$this->user1 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user1->save();
$this->user2 = User::create(['name' => $this->randomMachineName(), 'mail' => $this->randomMachineName() . '@example.com']);
$this->user2->save();
// Create new profiles.
$profile1 = Profile::create($expected = ['type' => $types['profile_type_0']->id(), 'uid' => $this->user1->id()]);
$profile1->save();
$profile2 = Profile::create($expected = ['type' => $types['profile_type_1']->id(), 'uid' => $this->user2->id()]);
$profile2->save();
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config');
$this->clickLink('User profiles');
$this->assertResponse(200);
$this->assertUrl('admin/config/people/profiles');
$this->assertLink($profile1->label());
$this->assertLinkByHref($profile2->toUrl('canonical')->toString());
}
示例15: setUpFixtures
/**
* {@inheritdoc}
*/
protected function setUpFixtures()
{
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test');
$this->installConfig(['entity_test']);
EntityViewMode::create(['id' => 'entity_test.foobar', 'targetEntityType' => 'entity_test', 'status' => TRUE, 'enabled' => TRUE, 'label' => 'My view mode'])->save();
$display = EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'foobar', 'label' => 'My view mode', 'status' => TRUE]);
$display->save();
$field_storage = FieldStorageConfig::create(['field_name' => 'test_field', 'entity_type' => 'entity_test', 'type' => 'string']);
$field_storage->save();
$field_config = FieldConfig::create(['field_name' => 'test_field', 'entity_type' => 'entity_test', 'bundle' => 'entity_test']);
$field_config->save();
// Create some test entities.
for ($i = 1; $i <= 3; $i++) {
EntityTest::create(['name' => "Article title {$i}", 'test_field' => "Test {$i}"])->save();
}
$this->user = User::create(['name' => 'test user']);
$this->user->save();
parent::setUpFixtures();
}