本文整理匯總了PHP中Drupal\user\Entity\Role::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::save方法的具體用法?PHP Role::save怎麽用?PHP Role::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\user\Entity\Role
的用法示例。
在下文中一共展示了Role::save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setUp
/**
* {@inheritdoc}
*/
function setUp()
{
parent::setUp();
$this->role1 = entity_create('user_role', array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
$this->role1->save();
$this->role2 = entity_create('user_role', array('id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(8)));
$this->role2->save();
entity_reference_create_instance('user', 'user', 'user_reference', 'User reference', 'user');
}
示例2: role_create
public function role_create($role_machine_name, $role_human_readable_name = '')
{
// In D6 and D7, when we create a new role, the role
// machine name is specified, and the numeric rid is
// auto-assigned (next available id); in D8, when we
// create a new role, we need to specify both the rid,
// which is now the role machine name, and also a human-readable
// role name. If the client did not provide a human-readable
// name, then we'll use the role machine name in its place.
if (empty($role_human_readable_name)) {
$role_human_readable_name = ucfirst($role_machine_name);
}
$role = new Role(array('id' => $role_machine_name, 'label' => $role_human_readable_name), 'user_role');
$role->save();
return $role;
}