本文整理匯總了PHP中Drupal\user\Entity\User::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::save方法的具體用法?PHP User::save怎麽用?PHP User::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\user\Entity\User
的用法示例。
在下文中一共展示了User::save方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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' => DRUPAL_ANONYMOUS_RID, 'label' => 'Anonymous user'))->save();
Role::create(array('id' => DRUPAL_AUTHENTICATED_RID, '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('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: setUpFixtures
/**
* {@inheritdoc}
*/
protected function setUpFixtures()
{
$this->installEntitySchema('user');
$this->installConfig(array('user'));
parent::setUpFixtures();
// Create a record for uid 1.
$this->rootUser = User::create(['name' => $this->randomMachineName()]);
$this->rootUser->save();
Views::viewsData()->clear();
}
示例3: setUpFixtures
/**
* Overrides \Drupal\views\Tests\ViewUnitTestBase::setUpFixtures().
*/
protected function setUpFixtures()
{
$this->installEntitySchema('user');
$this->installConfig(array('user'));
parent::setUpFixtures();
// Create a record for uid 1.
$this->installSchema('system', 'sequences');
$this->root_user = entity_create('user', array('name' => $this->randomMachineName()));
$this->root_user->save();
Views::viewsData()->clear();
}
示例4: setUp
protected function setUp()
{
parent::setUp();
// User create needs sequence table.
$this->installSchema('system', array('sequences'));
// Create a test user to use as the entity owner.
$this->user = \Drupal::entityManager()->getStorage('user')->create(['name' => 'serialization_test_user', 'mail' => 'foo@example.com', 'pass' => '123456']);
$this->user->save();
// Create a test entity to serialize.
$this->values = array('name' => $this->randomMachineName(), 'user_id' => $this->user->id(), 'field_test_text' => array('value' => $this->randomMachineName(), 'format' => 'full_html'));
$this->entity = entity_create('entity_test_mulrev', $this->values);
$this->entity->save();
$this->serializer = $this->container->get('serializer');
$this->installConfig(array('field'));
}