当前位置: 首页>>代码示例>>PHP>>正文


PHP Role::loadMultiple方法代码示例

本文整理汇总了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;
 }
开发者ID:nicolaspoulain,项目名称:bb8,代码行数:14,代码来源:MasqueradePermissions.php

示例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);
 }
开发者ID:dustinleblanc,项目名称:codeception-drupal-8,代码行数:16,代码来源:Drupal8.php

示例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);
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:26,代码来源:ProfileTypeForm.php

示例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;
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:30,代码来源:SpiController.php

示例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);
  }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:51,代码来源:MigrateUserRoleTest.php


注:本文中的Drupal\user\Entity\Role::loadMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。