本文整理汇总了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;
}