You are here

class UserPermissionsModuleSpecificForm in Drupal 10

Provides the user permissions administration form for one or more module(s).

@internal

Hierarchy

Expanded class hierarchy of UserPermissionsModuleSpecificForm

1 string reference to 'UserPermissionsModuleSpecificForm'
user.routing.yml in core/modules/user/user.routing.yml
core/modules/user/user.routing.yml

File

core/modules/user/src/Form/UserPermissionsModuleSpecificForm.php, line 14

Namespace

Drupal\user\Form
View source
class UserPermissionsModuleSpecificForm extends UserPermissionsForm {

  /**
   * The module list.
   *
   * A keyed array of module machine names.
   *
   * @var string[]
   */
  protected $moduleList;

  /**
   * {@inheritdoc}
   */
  protected function permissionsByProvider() : array {
    return array_intersect_key(parent::permissionsByProvider(), array_flip($this->moduleList));
  }

  /**
   * Builds the user permissions administration form for a specific module(s).
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   * @param string $modules
   *   (optional) One or more module machine names, comma-separated.
   */
  public function buildForm(array $form, FormStateInterface $form_state, $modules = '') : array {
    $this->moduleList = explode(',', $modules);
    return parent::buildForm($form, $form_state);
  }

  /**
   * Checks that at least one module defines permissions.
   *
   * @param string $modules
   *   (optional) One or more module machine names, comma-separated.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access($modules) : AccessResultInterface {
    foreach (explode(',', $modules) as $module) {
      if ($this->permissionHandler
        ->moduleProvidesPermissions($module)) {
        return AccessResult::allowed();
      }
    }
    return AccessResult::forbidden();
  }

}

Members