本文整理汇总了PHP中Drupal\user\Entity\Role::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::loadMultiple方法的具体用法?PHP Role::loadMultiple怎么用?PHP Role::loadMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\user\Entity\Role
的用法示例。
在下文中一共展示了Role::loadMultiple方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserRoles
/**
* Returns role entities allowed to masquerade as.
*
* @return \Drupal\user\RoleInterface[]
* An associative array with the role id as the key and the role object as
* value.
*/
protected function getUserRoles()
{
$roles = Role::loadMultiple();
// Do not allow masquerade as anonymous user, use private browsing.
unset($roles[RoleInterface::ANONYMOUS_ID]);
return $roles;
}
示例2: __construct
/**
* Drupal8Module constructor.
*/
public function __construct(ModuleContainer $container, $config = null)
{
$this->config = array_merge(['drupal_root' => Configuration::projectDir() . 'web', 'site_path' => 'sites/test', 'create_users' => true, 'destroy_users' => true, 'test_user_pass' => 'test'], (array) $config);
// Bootstrap a bare minimum Kernel so we can interact with Drupal.
$autoloader = (require $this->config['drupal_root'] . '/autoload.php');
$kernel = new TestDrupalKernel('prod', $autoloader, $this->config['drupal_root']);
$kernel->bootTestEnvironment($this->config['site_path']);
// Allow for setting some basic info output.
$this->output = new ConsoleOutput();
// Get our role definitions as we use them a lot.
$this->roles = Role::loadMultiple();
parent::__construct($container);
}
示例3: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
$type = $this->entity;
if ($this->operation == 'add') {
$form['#title'] = $this->t('Add profile type');
} else {
$form['#title'] = $this->t('Edit %label profile type', ['%label' => $type->label()]);
}
$form['label'] = ['#title' => t('Label'), '#type' => 'textfield', '#default_value' => $type->label(), '#description' => t('The human-readable name of this profile type.'), '#required' => TRUE, '#size' => 30];
$form['id'] = ['#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => ['exists' => '\\Drupal\\profile\\Entity\\ProfileType::load', 'source' => ['label']]];
$form['registration'] = ['#type' => 'checkbox', '#title' => t('Include in user registration form'), '#default_value' => $type->getRegistration()];
$form['multiple'] = ['#type' => 'checkbox', '#title' => t('Allow multiple profiles'), '#default_value' => $type->getMultiple()];
$form['roles'] = ['#type' => 'checkboxes', '#title' => t('Allowed roles'), '#description' => $this->t('Limit the users that can have this profile by role.</br><em>None will indicate that all users can have this profile type.</em>'), '#options' => [], '#default_value' => $type->getRoles()];
foreach (Role::loadMultiple() as $role) {
/** @var \Drupal\user\Entity\Role $role */
// We aren't interested in anon role.
if ($role->id() !== Role::ANONYMOUS_ID) {
$form['roles']['#options'][$role->id()] = $role->label();
}
}
return $this->protectBundleIdElement($form);
}
示例4: getAdminCount
/**
* The number of users who have admin-level user roles.
*
* @return int
*/
private function getAdminCount()
{
$roles_name = array();
$get_roles = Role::loadMultiple();
unset($get_roles[DRUPAL_ANONYMOUS_RID]);
$permission = array('administer permissions', 'administer users');
foreach ($permission as $key => $value) {
$filtered_roles = array_filter($get_roles, function ($role) use($value) {
return $role->hasPermission($value);
});
foreach ($filtered_roles as $role_name => $data) {
$roles_name[] = $role_name;
}
}
if (!empty($roles_name)) {
$roles_name_unique = array_unique($roles_name);
$query = db_select('user__roles', 'ur');
$query->fields('ur', array('entity_id'));
$query->condition('ur.bundle', 'user', '=');
$query->condition('ur.deleted', '0', '=');
$query->condition('ur.roles_target_id', $roles_name_unique, 'IN');
$count = $query->countQuery()->execute()->fetchField();
}
return isset($count) && is_numeric($count) ? $count : NULL;
}
示例5: testUserRole
/**
* Tests user role migration.
*/
public function testUserRole() {
$id_map = $this->getMigration('d6_user_role')->getIdMap();
$this->assertRoles($id_map);
// Test there are no duplicated roles.
$roles = [
'anonymous1',
'authenticated1',
'administrator1',
'migrate_test_role_11',
'migrate_test_role_21',
'migrate_test_role_3_that_is_longer_than_thirty_two_characters1'
];
$this->assertEmpty(Role::loadMultiple($roles));
// Remove the map row for the migrate_test_role_1 role and rerun the
// migration. This will re-import the migrate_test_role_1 role migration
// again.
$this->sourceDatabase->insert('role')
->fields([
'rid' => 6,
'name' => 'migrate test role 4',
])
->execute();
$this->sourceDatabase->insert('permission')
->fields([
'pid' => 7,
'rid' => 6,
'perm' => 'access content',
'tid' => 0,
])
->execute();
$id_map->delete(['rid' => 3]);
$this->executeMigration('d6_user_role');
// Test there are no duplicated roles.
$roles[] = 'migrate_test_role_41';
$this->assertEmpty(Role::loadMultiple($roles));
// Test that the existing roles have not changed.
$this->assertRoles($id_map);
// Test the migration of the new role, migrate_test_role_4.
$permissions = ['access content'];
$this->assertRole('migrate_test_role_4', $permissions, 6, $id_map);
}