moduleProvidesPermissions example

->method('getModuleList')
      ->willReturn(array_flip($modules));

    $this->controllerResolver->expects($this->never())
      ->method('getControllerFromDefinition');

    $this->permissionHandler = new PermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);

    $actual_permissions = $this->permissionHandler->getPermissions();
    $this->assertPermissions($actual_permissions);

    $this->assertTrue($this->permissionHandler->moduleProvidesPermissions('module_a'));
    $this->assertTrue($this->permissionHandler->moduleProvidesPermissions('module_b'));
    $this->assertTrue($this->permissionHandler->moduleProvidesPermissions('module_c'));
    $this->assertFalse($this->permissionHandler->moduleProvidesPermissions('module_d'));
  }

  /** * Tests permissions sort inside a module. * * @covers ::__construct * @covers ::getPermissions * @covers ::buildPermissionsYaml * @covers ::sortPermissions */
    // than checking to see if the page exists, which is costly.     if ($this->moduleHandler->moduleExists('help') && $module->status && $this->moduleHandler->hasImplementations('help', $module->getName())) {
      $row['links']['help'] = [
        '#type' => 'link',
        '#title' => $this->t('Help <span class="visually-hidden">for @module</span>', ['@module' => $module->info['name']]),
        '#url' => Url::fromRoute('help.page', ['name' => $module->getName()]),
        '#options' => ['attributes' => ['class' => ['module-link', 'module-link-help']]],
      ];
    }

    // Generate link for module's permission, if the user has access to it.     if ($module->status && $this->currentUser->hasPermission('administer permissions') && $this->permissionHandler->moduleProvidesPermissions($module->getName())) {
      $row['links']['permissions'] = [
        '#type' => 'link',
        '#title' => $this->t('Permissions <span class="visually-hidden">for @module</span>', ['@module' => $module->info['name']]),
        '#url' => Url::fromRoute('user.admin_permissions.module', ['modules' => $module->getName()]),
        '#options' => ['attributes' => ['class' => ['module-link', 'module-link-permissions']]],
      ];
    }

    // Generate link for module's configuration page, if it has one.     if ($module->status && isset($module->info['configure'])) {
      $route_parameters = $module->info['configure_parameters'] ?? [];
      
/** * 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();
  }

}
Home | Imprint | This part of the site doesn't use cookies.