summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-09-22 12:01:35 (GMT)
committerAlex Pott2014-09-22 12:01:35 (GMT)
commite1081c61d7fc5d0ee2a7de1bffb04cd4cc13cc88 (patch)
treee90f455b0804cb536b214d6803b983cf1e603254
parent5e938c16d17779aaef1d3213ab7360e09c8e9a87 (diff)
Issue #2338475 by herom: Remove hook_permission().
-rw-r--r--core/modules/system/core.api.php9
-rw-r--r--core/modules/system/system.api.php49
-rw-r--r--core/modules/user/src/Access/PermissionAccessCheck.php3
-rw-r--r--core/modules/user/src/PermissionHandler.php39
-rw-r--r--core/modules/user/tests/src/Unit/PermissionHandlerTest.php57
5 files changed, 10 insertions, 147 deletions
diff --git a/core/modules/system/core.api.php b/core/modules/system/core.api.php
index ff0ee61..ddd4974 100644
--- a/core/modules/system/core.api.php
+++ b/core/modules/system/core.api.php
@@ -550,11 +550,10 @@
* appropriately for their particular sites.
*
* @section sec_define Defining permissions
- * Modules define permissions via a $module.permissions.yml file or by
- * implementing hook_permission(). The return value defines machine names,
- * human-readable names, and optionally descriptions for each permission type.
- * The machine names are the canonical way to refer to permissions for access
- * checking.
+ * Modules define permissions via a $module.permissions.yml file. The return
+ * value defines machine names, human-readable names, and optionally
+ * descriptions for each permission type. The machine names are the canonical
+ * way to refer to permissions for access checking.
*
* @section sec_access Access permission checking
* Depending on the situation, there are several methods for ensuring that
diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php
index b859a28..ae416ed 100644
--- a/core/modules/system/system.api.php
+++ b/core/modules/system/system.api.php
@@ -943,55 +943,6 @@ function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $
}
/**
- * Define user permissions.
- *
- * This hook can supply permissions that the module defines, so that they
- * can be selected on the user permissions page and used to grant or restrict
- * access to actions the module performs.
- *
- * Permissions are checked using \Drupal::currentUser()->hasPermission().
- *
- * For a detailed usage example, see page_example.module.
- *
- * @return
- * An array whose keys are permission names and whose corresponding values
- * are arrays containing the following key-value pairs:
- * - title: The human-readable name of the permission, to be shown on the
- * permission administration page. This should be wrapped in the t()
- * function so it can be translated.
- * - description: (optional) A description of what the permission does. This
- * should be wrapped in the t() function so it can be translated.
- * - restrict access: (optional) A boolean which can be set to TRUE to
- * indicate that site administrators should restrict access to this
- * permission to trusted users. This should be used for permissions that
- * have inherent security risks across a variety of potential use cases
- * (for example, the "administer filters" and "bypass node access"
- * permissions provided by Drupal core). When set to TRUE, a standard
- * warning message defined in user_admin_permissions() will be displayed
- * with the permission on the permission administration page. Defaults
- * to FALSE.
- * - warning: (optional) A translated warning message to display for this
- * permission on the permission administration page. This warning overrides
- * the automatic warning generated by 'restrict access' being set to TRUE.
- * This should rarely be used, since it is important for all permissions to
- * have a clear, consistent security warning that is the same across the
- * site. Use the 'description' key instead to provide any information that
- * is specific to the permission you are defining.
- *
- * @ingroup user_api
- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- * Use $module.permissions.yml files.
- */
-function hook_permission() {
- return array(
- 'administer my module' => array(
- 'title' => t('Administer my module'),
- 'description' => t('Perform administration tasks for my module.'),
- ),
- );
-}
-
-/**
* Provide online user help.
*
* By implementing hook_help(), a module can make documentation available to
diff --git a/core/modules/user/src/Access/PermissionAccessCheck.php b/core/modules/user/src/Access/PermissionAccessCheck.php
index 6d10101..70c99db 100644
--- a/core/modules/user/src/Access/PermissionAccessCheck.php
+++ b/core/modules/user/src/Access/PermissionAccessCheck.php
@@ -13,7 +13,8 @@ use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
/**
- * Determines access to routes based on permissions defined via permissions.yml.
+ * Determines access to routes based on permissions defined via
+ * $module.permissions.yml files.
*/
class PermissionAccessCheck implements AccessInterface {
diff --git a/core/modules/user/src/PermissionHandler.php b/core/modules/user/src/PermissionHandler.php
index 36a6757..0ec4eee 100644
--- a/core/modules/user/src/PermissionHandler.php
+++ b/core/modules/user/src/PermissionHandler.php
@@ -14,18 +14,16 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
- * Provides the available permissions based on hook_permission and yml files.
+ * Provides the available permissions based on yml files.
*
* To define permissions you can use a $module.permissions.yml file:
*
* @code
- * 'access all views':
+ * access all views:
* title: 'Bypass views access control'
* description: 'Bypass access control when accessing views.'
- * 'restrict access': TRUE
- * @encode
- *
- * @see hook_permission()
+ * restrict access: true
+ * @endcode
*/
class PermissionHandler implements PermissionHandlerInterface {
@@ -89,8 +87,6 @@ class PermissionHandler implements PermissionHandlerInterface {
public function getPermissions() {
$all_permissions = $this->buildPermissionsYaml();
- $all_permissions += $this->buildPermissionsModules();
-
return $this->sortPermissions($all_permissions);
}
@@ -171,33 +167,6 @@ class PermissionHandler implements PermissionHandlerInterface {
}
/**
- * Builds all permissions provided by .module files.
- *
- * @return array[]
- * Each return permission is an array with the following keys:
- * - title: The title of the permission.
- * - description: The description of the permission, defaults to NULL.
- * - provider: The provider of the permission.
- */
- protected function buildPermissionsModules() {
- $all_permissions = array();
- foreach ($this->moduleHandler->getImplementations('permission') as $provider) {
- $permissions = $this->moduleHandler->invoke($provider, 'permission');
- foreach ($permissions as &$permission) {
- if (!is_array($permission)) {
- $permission = array(
- 'title' => $permission,
- 'description' => NULL,
- );
- }
- $permission['provider'] = $provider;
- }
- $all_permissions += $permissions;
- }
- return $all_permissions;
- }
-
- /**
* Sorts the given permissions by provider name and title.
*
* @param array $all_permissions
diff --git a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
index 013986d..858b8d6 100644
--- a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
+++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php
@@ -77,63 +77,6 @@ class PermissionHandlerTest extends UnitTestCase {
}
/**
- * Tests permissions by hook_permission.
- *
- * @covers ::__construct
- * @covers ::getPermissions
- * @covers ::buildPermissions
- * @covers ::buildPermissionsModules
- * @covers ::sortPermissions
- * @covers ::getModuleNames
- */
- public function testBuildPermissionsModules() {
- $modules = array('module_a', 'module_b', 'module_c');
- $extensions = array(
- 'module_a' => $this->mockModuleExtension('module_a', 'Module a'),
- 'module_b' => $this->mockModuleExtension('module_b', 'Moduleb'),
- 'module_c' => $this->mockModuleExtension('module_c', 'Module c'),
- );
- $permissions = array(
- 'module_a' => array('access_module_a' => 'single_description'),
- 'module_b' => array('access module b' => array('title' => 'Access B', 'description' => 'bla bla')),
- 'module_c' => array('access_module_c' => array('title' => 'Access C', 'description' => 'bla bla', 'restrict access' => TRUE)),
- );
- $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
- $this->moduleHandler->expects($this->once())
- ->method('getModuleDirectories')
- ->willReturn([]);
-
- $this->moduleHandler->expects($this->at(1))
- ->method('getImplementations')
- ->with('permission')
- ->willReturn($modules);
-
- // Setup the module handler.
- $i = 2;
- foreach ($modules as $module_name) {
- $this->moduleHandler->expects($this->at($i++))
- ->method('invoke')
- ->with($module_name)
- ->willReturn($permissions[$module_name]);
- }
- $this->moduleHandler->expects($this->any())
- ->method('getModuleList')
- ->willReturn(array_flip($modules));
-
- $this->permissionHandler = new TestPermissionHandler($this->moduleHandler, $this->stringTranslation, $this->controllerResolver);
-
- // Setup system_rebuild_module_data().
- $this->permissionHandler->setSystemRebuildModuleData($extensions);
-
- $actual_permissions = $this->permissionHandler->getPermissions();
- $this->assertPermissions($actual_permissions);
- // Ensure that the human name of the module is taken into account for the
- // sorting.
- $this->assertSame(array('access_module_a', 'access_module_c', 'access module b'), array_keys($actual_permissions));
- }
-
-
- /**
* Tests permissions provided by YML files.
*
* @covers ::__construct