diff --git a/core/modules/action/action.module b/core/modules/action/action.module index 5e0412e..f1cde81 100644 --- a/core/modules/action/action.module +++ b/core/modules/action/action.module @@ -35,17 +35,6 @@ function action_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function action_permission() { - return array( - 'administer actions' => array( - 'title' => t('Administer actions'), - ), - ); -} - -/** * Implements hook_entity_type_build(). */ function action_entity_type_build(array &$entity_types) { diff --git a/core/modules/action/action.permissions.yml b/core/modules/action/action.permissions.yml new file mode 100644 index 0000000..0f00dcd --- /dev/null +++ b/core/modules/action/action.permissions.yml @@ -0,0 +1,2 @@ +administer actions: + title: 'Administer actions' diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 64eb275..7361345 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -93,20 +93,6 @@ function aggregator_theme() { } /** - * Implements hook_permission(). - */ -function aggregator_permission() { - return array( - 'administer news feeds' => array( - 'title' => t('Administer news feeds'), - ), - 'access news feeds' => array( - 'title' => t('View news feeds'), - ), - ); -} - -/** * Implements hook_cron(). * * Queues news feeds for updates once their refresh interval has elapsed. diff --git a/core/modules/aggregator/aggregator.permissions.yml b/core/modules/aggregator/aggregator.permissions.yml new file mode 100644 index 0000000..e96ddb4 --- /dev/null +++ b/core/modules/aggregator/aggregator.permissions.yml @@ -0,0 +1,4 @@ +administer news feeds: + title: 'Administer news feeds' +access news feeds: + title: 'View news feeds' diff --git a/core/modules/ban/ban.module b/core/modules/ban/ban.module index 2d048d4..b6270af 100644 --- a/core/modules/ban/ban.module +++ b/core/modules/ban/ban.module @@ -27,14 +27,3 @@ function ban_help($route_name, RouteMatchInterface $route_match) { return '

' . t('IP addresses listed here are banned from your site. Banned addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '

'; } } - -/** - * Implements hook_permission(). - */ -function ban_permission() { - return array( - 'ban IP addresses' => array( - 'title' => t('Ban IP addresses'), - ), - ); -} diff --git a/core/modules/ban/ban.permissions.yml b/core/modules/ban/ban.permissions.yml new file mode 100644 index 0000000..7f385fd --- /dev/null +++ b/core/modules/ban/ban.permissions.yml @@ -0,0 +1,2 @@ +ban IP addresses: + title: 'Ban IP addresses' diff --git a/core/modules/block/block.module b/core/modules/block/block.module index e9d9333..8e6c48f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -63,17 +63,6 @@ function block_theme() { } /** - * Implements hook_permission(). - */ -function block_permission() { - return array( - 'administer blocks' => array( - 'title' => t('Administer blocks'), - ), - ); -} - -/** * Implements hook_page_build(). * * Renders blocks into their regions. diff --git a/core/modules/block/block.permissions.yml b/core/modules/block/block.permissions.yml new file mode 100644 index 0000000..83f35cd --- /dev/null +++ b/core/modules/block/block.permissions.yml @@ -0,0 +1,2 @@ +administer blocks: + title: 'Administer blocks' diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 5e87f43..f72c183 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -83,27 +83,6 @@ function book_theme() { } /** - * Implements hook_permission(). - */ -function book_permission() { - return array( - 'administer book outlines' => array( - 'title' => t('Administer book outlines'), - ), - 'create new books' => array( - 'title' => t('Create new books'), - ), - 'add content to books' => array( - 'title' => t('Add content and child pages to books'), - ), - 'access printer-friendly version' => array( - 'title' => t('View printer-friendly books'), - 'description' => t('View a book page and all of its sub-pages as a single document for ease of printing. Can be performance heavy.'), - ), - ); -} - -/** * Implements hook_entity_type_build(). */ function book_entity_type_build(array &$entity_types) { diff --git a/core/modules/book/book.permissions.yml b/core/modules/book/book.permissions.yml new file mode 100644 index 0000000..52dd9d0 --- /dev/null +++ b/core/modules/book/book.permissions.yml @@ -0,0 +1,9 @@ +administer book outlines: + title: 'Administer book outlines' +create new books: + title: 'Create new books' +add content to books: + title: 'Add content and child pages to books' +access printer-friendly version: + title: 'View printer-friendly books' + description: 'View a book page and all of its sub-pages as a single document for ease of printing. Can be performance heavy.' diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index dbe3bee..b13d881 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -198,33 +198,6 @@ function comment_field_instance_config_delete(FieldInstanceConfigInterface $inst } /** - * Implements hook_permission(). - */ -function comment_permission() { - return array( - 'administer comments' => array( - 'title' => t('Administer comments and comment settings'), - ), - 'administer comment types' => array( - 'title' => t('Administer comment types and settings'), - 'restrict access' => TRUE, - ), - 'access comments' => array( - 'title' => t('View comments'), - ), - 'post comments' => array( - 'title' => t('Post comments'), - ), - 'skip comment approval' => array( - 'title' => t('Skip comment approval'), - ), - 'edit own comments' => array( - 'title' => t('Edit own comments'), - ), - ); -} - -/** * Implements hook_entity_build_defaults_alter(). */ function comment_entity_build_defaults_alter(array &$build, EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { diff --git a/core/modules/comment/comment.permissions.yml b/core/modules/comment/comment.permissions.yml new file mode 100644 index 0000000..664b5e1 --- /dev/null +++ b/core/modules/comment/comment.permissions.yml @@ -0,0 +1,13 @@ +administer comments: + title: 'Administer comments and comment settings' +administer comment types: + title: 'Administer comment types and settings' + restrict access: true +access comments: + title: 'View comments' +post comments: + title: 'Post comments' +skip comment approval: + title: 'Skip comment approval' +edit own comments: + title: 'Edit own comments' diff --git a/core/modules/config/config.module b/core/modules/config/config.module index e22b71b..84e0210 100644 --- a/core/modules/config/config.module +++ b/core/modules/config/config.module @@ -28,25 +28,6 @@ function config_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function config_permission() { - $permissions['synchronize configuration'] = array( - 'title' => t('Synchronize configuration'), - 'restrict access' => TRUE, - ); - $permissions['export configuration'] = array( - 'title' => t('Export configuration'), - 'restrict access' => TRUE, - ); - $permissions['import configuration'] = array( - 'title' => t('Import configuration'), - 'restrict access' => TRUE, - ); - return $permissions; -} - -/** * Implements hook_file_download(). */ function config_file_download($uri) { diff --git a/core/modules/config/config.permissions.yml b/core/modules/config/config.permissions.yml new file mode 100644 index 0000000..ee24216 --- /dev/null +++ b/core/modules/config/config.permissions.yml @@ -0,0 +1,9 @@ +synchronize configuration: + title: 'Synchronize configuration' + restrict access: true +export configuration: + title: 'Export configuration' + restrict access: true +import configuration: + title: 'Import configuration' + restrict access: true diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index 43aa754..6958c80 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -37,18 +37,6 @@ function config_translation_help($route_name, RouteMatchInterface $route_match) } /** - * Implements hook_permission(). - */ -function config_translation_permission() { - return array( - 'translate configuration' => array( - 'title' => t('Translate user edited configuration'), - 'description' => t('Translate any configuration not shipped with modules and themes.'), - ), - ); -} - -/** * Implements hook_theme(). */ function config_translation_theme() { diff --git a/core/modules/config_translation/config_translation.permissions.yml b/core/modules/config_translation/config_translation.permissions.yml new file mode 100644 index 0000000..bbba883 --- /dev/null +++ b/core/modules/config_translation/config_translation.permissions.yml @@ -0,0 +1,3 @@ +translate configuration: + title: 'Translate user edited configuration' + description: 'Translate any configuration not shipped with modules and themes.' diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index ac073eb..6a83335 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -39,23 +39,6 @@ function contact_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function contact_permission() { - return array( - 'administer contact forms' => array( - 'title' => t('Administer contact forms and contact form settings'), - ), - 'access site-wide contact form' => array( - 'title' => t('Use the site-wide contact form'), - ), - 'access user contact forms' => array( - 'title' => t("Use users' personal contact forms"), - ), - ); -} - -/** * Implements hook_entity_type_alter(). */ function contact_entity_type_alter(array &$entity_types) { diff --git a/core/modules/contact/contact.permissions.yml b/core/modules/contact/contact.permissions.yml new file mode 100644 index 0000000..c04534d --- /dev/null +++ b/core/modules/contact/contact.permissions.yml @@ -0,0 +1,6 @@ +administer contact forms: + title: 'Administer contact forms and contact form settings' +access site-wide contact form: + title: 'Use the site-wide contact form' +access user contact forms: + title: 'Use users'' personal contact forms' diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index dddad7c..5bf47f5 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -359,24 +359,7 @@ function content_translation_access(EntityInterface $entity, $op) { * Implements hook_permission(). */ function content_translation_permission() { - $permission = array( - 'administer content translation' => array( - 'title' => t('Administer translation settings'), - 'description' => t('Configure translatability of entities and fields.'), - ), - 'create content translations' => array( - 'title' => t('Create translations'), - ), - 'update content translations' => array( - 'title' => t('Edit translations'), - ), - 'delete content translations' => array( - 'title' => t('Delete translations'), - ), - 'translate any entity' => array( - 'title' => t('Translate any entity'), - ), - ); + $permission = []; // Create a translate permission for each enabled entity type and (optionally) // bundle. diff --git a/core/modules/content_translation/content_translation.permissions.yml b/core/modules/content_translation/content_translation.permissions.yml new file mode 100644 index 0000000..1184692 --- /dev/null +++ b/core/modules/content_translation/content_translation.permissions.yml @@ -0,0 +1,11 @@ +administer content translation: + title: 'Administer translation settings' + description: 'Configure translatability of entities and fields.' +create content translations: + title: 'Create translations' +update content translations: + title: 'Edit translations' +delete content translations: + title: 'Delete translations' +translate any entity: + title: 'Translate any entity' diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index b799a5a..47dc049 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -87,18 +87,6 @@ function contextual_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function contextual_permission() { - return array( - 'access contextual links' => array( - 'title' => t('Use contextual links'), - 'description' => t('Use contextual links to perform actions related to elements on a page.'), - ), - ); -} - -/** * Implements hook_element_info(). */ function contextual_element_info() { diff --git a/core/modules/contextual/contextual.permissions.yml b/core/modules/contextual/contextual.permissions.yml new file mode 100644 index 0000000..1798b1f --- /dev/null +++ b/core/modules/contextual/contextual.permissions.yml @@ -0,0 +1,3 @@ +access contextual links: + title: 'Use contextual links' + description: 'Use contextual links to perform actions related to elements on a page.' diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index b70d4e3..be11cad 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -34,17 +34,6 @@ function entity_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function entity_permission() { - return array( - 'administer display modes' => array( - 'title' => t('Add, edit, and delete custom display modes.'), - ), - ); -} - -/** * Implements hook_entity_type_alter(). */ function entity_entity_type_alter(array &$entity_types) { diff --git a/core/modules/entity/entity.permissions.yml b/core/modules/entity/entity.permissions.yml new file mode 100644 index 0000000..8149e15 --- /dev/null +++ b/core/modules/entity/entity.permissions.yml @@ -0,0 +1,2 @@ +administer display modes: + title: 'Add, edit, and delete custom display modes.' diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 499c883..a419156 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -21,23 +21,6 @@ require_once __DIR__ . '/field_test.field.inc'; /** - * Implements hook_permission(). - */ -function field_test_permission() { - $perms = array( - 'view test_view_field content' => array( - 'title' => t('View test field content'), - 'description' => t('View published test_view_field content.'), - ), - 'administer field_test content' => array( - 'title' => t('Administer field_test content'), - 'description' => t('Manage field_test content'), - ), - ); - return $perms; -} - -/** * Store and retrieve keyed data for later verification by unit tests. * * This function is a simple in-memory key-value store with the diff --git a/core/modules/field/tests/modules/field_test/field_test.permissions.yml b/core/modules/field/tests/modules/field_test/field_test.permissions.yml new file mode 100644 index 0000000..a950bc7 --- /dev/null +++ b/core/modules/field/tests/modules/field_test/field_test.permissions.yml @@ -0,0 +1,6 @@ +view test_view_field content: + title: 'View test field content' + description: 'View published test_view_field content.' +administer field_test content: + title: 'Administer field_test content' + description: 'Manage field_test content' diff --git a/core/modules/file/file.module b/core/modules/file/file.module index e17ab46..6b3616c 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1890,20 +1890,6 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface } /** - * Implements hook_permission(). - */ -function file_permission() { - $perms = array( - 'access files overview' => array( - 'title' => t('Access the Files overview page'), - 'description' => t('Get an overview of all files.', array('!url' => url('admin/content/files'))), - ), - ); - - return $perms; -} - -/** * Formats human-readable version of file status. * * @param int $choice diff --git a/core/modules/file/file.permissions.yml b/core/modules/file/file.permissions.yml new file mode 100644 index 0000000..0572874 --- /dev/null +++ b/core/modules/file/file.permissions.yml @@ -0,0 +1,3 @@ +access files overview: + title: 'Access the Files overview page' + description: 'Get an overview of all files.' diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 3fa834b..1c3ebcf 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -228,14 +228,7 @@ function filter_pre_render_text(array $element) { * Implements hook_permission(). */ function filter_permission() { - $perms['administer filters'] = array( - 'title' => t('Administer text formats and filters'), - 'description' => t('Define how text is handled by combining filters into text formats.', array( - '@url' => url('admin/config/content/formats'), - )), - 'restrict access' => TRUE, - ); - + $perms = []; // Generate permissions for each text format. Warn the administrator that any // of them are potentially unsafe. foreach (filter_formats() as $format) { diff --git a/core/modules/filter/filter.permissions.yml b/core/modules/filter/filter.permissions.yml new file mode 100644 index 0000000..2d15269 --- /dev/null +++ b/core/modules/filter/filter.permissions.yml @@ -0,0 +1,4 @@ +administer filters: + title: 'Administer text formats and filters' + description: 'Define how text is handled by combining filters into text formats.' + restrict access: true diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 039c305..0e7087d 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -344,18 +344,6 @@ function forum_node_storage_load($nodes) { } /** - * Implements hook_permission(). - */ -function forum_permission() { - $perms = array( - 'administer forums' => array( - 'title' => t('Administer forums'), - ), - ); - return $perms; -} - -/** * Implements hook_ENTITY_TYPE_update() for comment entities. */ function forum_comment_update(CommentInterface $comment) { diff --git a/core/modules/forum/forum.permissions.yml b/core/modules/forum/forum.permissions.yml new file mode 100644 index 0000000..ed8ddb4 --- /dev/null +++ b/core/modules/forum/forum.permissions.yml @@ -0,0 +1,2 @@ +administer forums: + title: 'Administer forums' diff --git a/core/modules/image/image.module b/core/modules/image/image.module index a6ce171..998db33 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -153,18 +153,6 @@ function image_theme() { } /** - * Implements hook_permission(). - */ -function image_permission() { - return array( - 'administer image styles' => array( - 'title' => t('Administer image styles'), - 'description' => t('Create and modify styles for generating image modifications such as thumbnails.'), - ), - ); -} - -/** * Implements hook_file_download(). * * Control the access to files underneath the styles directory. diff --git a/core/modules/image/image.permissions.yml b/core/modules/image/image.permissions.yml new file mode 100644 index 0000000..bc07792 --- /dev/null +++ b/core/modules/image/image.permissions.yml @@ -0,0 +1,3 @@ +administer image styles: + title: 'Administer image styles' + description: 'Create and modify styles for generating image modifications such as thumbnails.' diff --git a/core/modules/language/language.module b/core/modules/language/language.module index e095d8d..ee0a7dc 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -91,17 +91,6 @@ function language_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function language_permission() { - return array( - 'administer languages' => array( - 'title' => t('Administer languages'), - ), - ); -} - -/** * Implements hook_theme(). */ function language_theme() { diff --git a/core/modules/language/language.permissions.yml b/core/modules/language/language.permissions.yml new file mode 100644 index 0000000..85c3b91 --- /dev/null +++ b/core/modules/language/language.permissions.yml @@ -0,0 +1,2 @@ +administer languages: + title: 'Administer languages' diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 3122f59..11ffc27 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -174,18 +174,6 @@ function locale_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function locale_permission() { - return array( - 'translate interface' => array( - 'title' => t('Translate interface texts'), - 'restrict access' => TRUE, - ), - ); -} - -/** * Implements hook_theme(). */ function locale_theme() { diff --git a/core/modules/locale/locale.permissions.yml b/core/modules/locale/locale.permissions.yml new file mode 100644 index 0000000..8d37e89 --- /dev/null +++ b/core/modules/locale/locale.permissions.yml @@ -0,0 +1,3 @@ +translate interface: + title: 'Translate interface texts' + restrict access: true diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 69c23e3..96ae3fa 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -54,17 +54,6 @@ function menu_ui_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function menu_ui_permission() { - return array( - 'administer menu' => array( - 'title' => t('Administer menus and menu items'), - ), - ); -} - -/** * Implements hook_entity_type_build(). */ function menu_ui_entity_type_build(array &$entity_types) { diff --git a/core/modules/menu_ui/menu_ui.permissions.yml b/core/modules/menu_ui/menu_ui.permissions.yml new file mode 100644 index 0000000..9bc104f --- /dev/null +++ b/core/modules/menu_ui/menu_ui.permissions.yml @@ -0,0 +1,2 @@ +administer menu: + title: 'Administer menus and menu items' diff --git a/core/modules/node/node.permissions.yml b/core/modules/node/node.permissions.yml index 31a4992..6c7ea02 100644 --- a/core/modules/node/node.permissions.yml +++ b/core/modules/node/node.permissions.yml @@ -1,14 +1,17 @@ bypass node access: title: 'Bypass content access control' - description: 'View edit and delete all content regardless of permission restrictions.' - 'restrict access': TRUE + description: 'View, edit and delete all content regardless of permission restrictions.' + restrict access: true administer content types: title: 'Administer content types' - description: 'Promote change ownership edit revisions and perform other tasks across all content types.' - 'restrict access': TRUE + description: 'Promote, change ownership, edit revisions, and perform other tasks across all content types.' + restrict access: true administer nodes: title: 'Administer content' - 'restrict access': TRUE + restrict access: true +access content overview: + title: 'Access the Content overview page' + description: 'Get an overview of all content.' access content: title: 'View published content' view own unpublished content: diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index 797cf25..2361423 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -112,22 +112,6 @@ function node_access_test_node_access_records(NodeInterface $node) { } /** - * Implements hook_permission(). - * - * Provides a 'node test view' permission. By default, all content is - * restricted, and users without this permission can only view content they - * have authored. When the 'node_access_test.private' state variable is - * TRUE, only 'private' nodes are restricted, and this permission grants access - * to view private nodes. - * - * @see node_access_test_node_access_records() - * @see node_access_test_node_grants() - */ -function node_access_test_permission() { - return array('node test view' => array('title' => 'View content')); -} - -/** * Adds the private field to a node type. * * @param \Drupal\node\NodeTypeInterface $type diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.permissions.yml b/core/modules/node/tests/modules/node_access_test/node_access_test.permissions.yml new file mode 100644 index 0000000..5e52fa0 --- /dev/null +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.permissions.yml @@ -0,0 +1,2 @@ +node test view: + title: 'View content' diff --git a/core/modules/path/path.module b/core/modules/path/path.module index 0bf3781..ad99d4a 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -39,20 +39,6 @@ function path_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function path_permission() { - return array( - 'administer url aliases' => array( - 'title' => t('Administer URL aliases'), - ), - 'create url aliases' => array( - 'title' => t('Create and edit URL aliases'), - ), - ); -} - -/** * Implements hook_form_BASE_FORM_ID_alter() for node_form(). */ function path_form_node_form_alter(&$form, FormStateInterface $form_state) { diff --git a/core/modules/path/path.permissions.yml b/core/modules/path/path.permissions.yml new file mode 100644 index 0000000..c194de4 --- /dev/null +++ b/core/modules/path/path.permissions.yml @@ -0,0 +1,4 @@ +administer url aliases: + title: 'Administer URL aliases' +create url aliases: + title: 'Create and edit URL aliases' diff --git a/core/modules/quickedit/quickedit.module b/core/modules/quickedit/quickedit.module index f02fe3d..6b5a9cf 100644 --- a/core/modules/quickedit/quickedit.module +++ b/core/modules/quickedit/quickedit.module @@ -35,18 +35,6 @@ function quickedit_help($route_name, RouteMatchInterface $route_match) { } } - -/** - * Implements hook_permission(). - */ -function quickedit_permission() { - return array( - 'access in-place editing' => array( - 'title' => t('Access in-place editing'), - ), - ); -} - /** * Implements hook_page_build(). * diff --git a/core/modules/quickedit/quickedit.permissions.yml b/core/modules/quickedit/quickedit.permissions.yml new file mode 100644 index 0000000..f9ff51c --- /dev/null +++ b/core/modules/quickedit/quickedit.permissions.yml @@ -0,0 +1,2 @@ +access in-place editing: + title: 'Access in-place editing' diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index d8985c9..63c732a 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -41,17 +41,6 @@ function responsive_image_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function responsive_image_permission() { - return array( - 'administer responsive images' => array( - 'title' => t('Administer responsive images'), - ), - ); -} - -/** * Implements hook_menu(). */ function responsive_image_menu() { diff --git a/core/modules/responsive_image/responsive_image.permissions.yml b/core/modules/responsive_image/responsive_image.permissions.yml new file mode 100644 index 0000000..ad54cc8 --- /dev/null +++ b/core/modules/responsive_image/responsive_image.permissions.yml @@ -0,0 +1,2 @@ +administer responsive images: + title: 'Administer responsive images' diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 7cbe706..eef49c5 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -110,23 +110,6 @@ function search_theme() { } /** - * Implements hook_permission(). - */ -function search_permission() { - return array( - 'administer search' => array( - 'title' => t('Administer search'), - ), - 'search content' => array( - 'title' => t('Use search'), - ), - 'use advanced search' => array( - 'title' => t('Use advanced search'), - ), - ); -} - -/** * Implements hook_preprocess_HOOK() for block templates. */ function search_preprocess_block(&$variables) { diff --git a/core/modules/search/search.permissions.yml b/core/modules/search/search.permissions.yml new file mode 100644 index 0000000..346d848 --- /dev/null +++ b/core/modules/search/search.permissions.yml @@ -0,0 +1,6 @@ +administer search: + title: 'Administer search' +search content: + title: 'Use search' +use advanced search: + title: 'Use advanced search' diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 9dc7d5a..ef3f59b 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -45,28 +45,6 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function shortcut_permission() { - return array( - 'administer shortcuts' => array( - 'title' => t('Administer shortcuts'), - ), - 'customize shortcut links' => array( - 'title' => t('Edit current shortcut set'), - 'description' => t('Editing the current shortcut set will affect other users if that set has been assigned to or selected by other users. Granting "Select any shortcut set" permission along with this permission will grant permission to edit any shortcut set.'), - ), - 'switch shortcut sets' => array( - 'title' => t('Select any shortcut set'), - 'description' => t('From all shortcut sets, select one to be own active set. Without this permission, an administrator selects shortcut sets for users.'), - ), - 'access shortcuts' => array( - 'title' => t('Use shortcuts'), - ), - ); -} - -/** * Access callback for editing a shortcut set. * * @param Drupal\shortcut\ShortcutSetInterface $shortcut_set diff --git a/core/modules/shortcut/shortcut.permissions.yml b/core/modules/shortcut/shortcut.permissions.yml new file mode 100644 index 0000000..3ee20cf --- /dev/null +++ b/core/modules/shortcut/shortcut.permissions.yml @@ -0,0 +1,10 @@ +administer shortcuts: + title: 'Administer shortcuts' +customize shortcut links: + title: 'Edit current shortcut set' + description: 'Editing the current shortcut set will affect other users if that set has been assigned to or selected by other users. Granting "Select any shortcut set" permission along with this permission will grant permission to edit any shortcut set.' +switch shortcut sets: + title: 'Select any shortcut set' + description: 'From all shortcut sets, select one to be own active set. Without this permission, an administrator selects shortcut sets for users.' +access shortcuts: + title: 'Use shortcuts' diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 24665c7..d45bd36 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -38,18 +38,6 @@ function simpletest_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function simpletest_permission() { - return array( - 'administer unit tests' => array( - 'title' => t('Administer tests'), - 'restrict access' => TRUE, - ), - ); -} - -/** * Implements hook_theme(). */ function simpletest_theme() { diff --git a/core/modules/simpletest/simpletest.permissions.yml b/core/modules/simpletest/simpletest.permissions.yml new file mode 100644 index 0000000..a23e8c8 --- /dev/null +++ b/core/modules/simpletest/simpletest.permissions.yml @@ -0,0 +1,3 @@ +administer unit tests: + title: 'Administer tests' + restrict access: true diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index c8a8987..4c07c64 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -40,10 +40,11 @@ function testSetUp() { $table = 'entity_test'; // Verify that specified $modules have been loaded. - $this->assertTrue(function_exists('entity_test_permission'), 'entity_test.module was loaded.'); + $this->assertTrue(function_exists('entity_test_entity_bundle_info'), 'entity_test.module was loaded.'); // Verify that there is a fixed module list. $this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), $modules); - $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('permission'), $modules); + $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_bundle_info'), ['entity_test']); + $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('entity_bundle_rename'), ['entity']); // Verify that no modules have been installed. $this->assertFalse(db_table_exists($table), "'$table' database table not found."); @@ -69,8 +70,8 @@ function testEnableModulesLoad() { $this->assertTrue(\Drupal::moduleHandler()->moduleExists($module), "$module module found."); $list = array_keys(\Drupal::moduleHandler()->getModuleList()); $this->assertTrue(in_array($module, $list), "$module module found in the extension handler's module list."); - $list = \Drupal::moduleHandler()->getImplementations('permission'); - $this->assertTrue(in_array($module, $list), "{$module}_permission() in \Drupal::moduleHandler()->getImplementations() found."); + $list = \Drupal::moduleHandler()->getImplementations('query_efq_table_prefixing_test_alter'); + $this->assertTrue(in_array($module, $list), "{$module}_query_efq_table_prefixing_test_alter() in \Drupal::moduleHandler()->getImplementations() found."); } /** diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index bb52373..7e4927b 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -34,20 +34,6 @@ function statistics_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function statistics_permission() { - return array( - 'administer statistics' => array( - 'title' => t('Administer statistics'), - ), - 'view post access counter' => array( - 'title' => t('View content hits'), - ), - ); -} - -/** * Implements hook_ENTITY_TYPE_view() for node entities. */ function statistics_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) { diff --git a/core/modules/statistics/statistics.permissions.yml b/core/modules/statistics/statistics.permissions.yml new file mode 100644 index 0000000..b414c22 --- /dev/null +++ b/core/modules/statistics/statistics.permissions.yml @@ -0,0 +1,4 @@ +administer statistics: + title: 'Administer statistics' +view post access counter: + title: 'View content hits' diff --git a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php index 319e3be..8d5d229 100644 --- a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php +++ b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php @@ -39,14 +39,14 @@ function testModuleImplementsAlter() { 'The \Drupal::moduleHandler() instance has been replaced during \Drupal::moduleHandler()->install().'); // Assert that module_test.module is now included. - $this->assertTrue(function_exists('module_test_permission'), + $this->assertTrue(function_exists('module_test_modules_installed'), 'The file module_test.module was successfully included.'); $this->assertTrue(array_key_exists('module_test', \Drupal::moduleHandler()->getModuleList()), 'module_test is in the module list.'); - $this->assertTrue(in_array('module_test', \Drupal::moduleHandler()->getImplementations('permission')), - 'module_test implements hook_permission().'); + $this->assertTrue(in_array('module_test', \Drupal::moduleHandler()->getImplementations('modules_installed')), + 'module_test implements hook_modules_installed().'); $this->assertTrue(in_array('module_test', \Drupal::moduleHandler()->getImplementations('module_implements_alter')), 'module_test implements hook_module_implements_alter().'); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index f3b65a2..2320e67 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -217,47 +217,6 @@ function system_theme() { } /** - * Implements hook_permission(). - */ -function system_permission() { - return array( - 'administer modules' => array( - 'title' => t('Administer modules'), - ), - 'administer site configuration' => array( - 'title' => t('Administer site configuration'), - 'restrict access' => TRUE, - ), - 'administer themes' => array( - 'title' => t('Administer themes'), - ), - 'administer software updates' => array( - 'title' => t('Administer software updates'), - 'restrict access' => TRUE, - ), - 'access administration pages' => array( - 'title' => t('Use the administration pages and help'), - ), - 'access site in maintenance mode' => array( - 'title' => t('Use the site in maintenance mode'), - ), - 'view the administration theme' => array( - 'title' => t('View the administration theme'), - 'description' => t('This is only used when the site is configured to use a separate administration theme on the Appearance page.', array('@appearance-url' => url('admin/appearance'))), - ), - 'access site reports' => array( - 'title' => t('View site reports'), - 'restrict access' => TRUE, - ), - 'link to any page' => [ - 'title' => t('Link to any page'), - 'description' => t('This allows to bypass access checking when linking to internal paths.'), - 'restrict access' => TRUE, - ], - ); -} - -/** * Implements hook_hook_info(). */ function system_hook_info() { @@ -1118,7 +1077,13 @@ function system_get_module_admin_tasks($module, array $info) { } // Append link for permissions. - if (\Drupal::moduleHandler()->implementsHook($module, 'permission')) { + $permissions = \Drupal::service('user.permissions')->getPermissions(); + $permission_modules = []; + foreach ($permissions as $permission) { + $permission_modules[$permission['provider']] = $permission['provider']; + } + + if (isset($permission_modules[$module])) { /** @var \Drupal\Core\Access\AccessManagerInterface $access_manager */ $access_manager = \Drupal::service('access_manager'); if ($access_manager->checkNamedRoute('user.admin_permissions', array(), \Drupal::currentUser())) { diff --git a/core/modules/system/system.permissions.yml b/core/modules/system/system.permissions.yml new file mode 100644 index 0000000..44bb5ef --- /dev/null +++ b/core/modules/system/system.permissions.yml @@ -0,0 +1,24 @@ +administer modules: + title: 'Administer modules' +administer site configuration: + title: 'Administer site configuration' + restrict access: true +administer themes: + title: 'Administer themes' +administer software updates: + title: 'Administer software updates' + restrict access: true +access administration pages: + title: 'Use the administration pages and help' +access site in maintenance mode: + title: 'Use the site in maintenance mode' +view the administration theme: + title: 'View the administration theme' + description: 'This is only used when the site is configured to use a separate administration theme on the Appearance page.' +access site reports: + title: 'View site reports' + restrict access: true +link to any page: + title: 'Link to any page' + restrict access: true + description: 'This allows to bypass access checking when linking to internal paths.' diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index df110c2..fbe4d05 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -225,25 +225,6 @@ function entity_test_entity_extra_field_info() { } /** - * Implements hook_permission(). - */ -function entity_test_permission() { - $permissions = array( - 'administer entity_test content' => array( - 'title' => t('Administer entity_test content'), - 'description' => t('Manage entity_test content'), - ), - 'view test entity' => array( - 'title' => t('View test entities'), - ), - 'view test entity translations' => array( - 'title' => t('View translations of test entities'), - ), - ); - return $permissions; -} - -/** * Implements hook_form_BASE_FORM_ID_alter(). */ function entity_test_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) { diff --git a/core/modules/system/tests/modules/entity_test/entity_test.permissions.yml b/core/modules/system/tests/modules/entity_test/entity_test.permissions.yml new file mode 100644 index 0000000..e6b705e --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/entity_test.permissions.yml @@ -0,0 +1,7 @@ +administer entity_test content: + title: 'Administer entity_test content' + description: 'Manage entity_test content' +view test entity: + title: 'View test entities' +view test entity translations: + title: 'View translations of test entities' diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index ad38397..5cd85a3 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -8,21 +8,6 @@ use Drupal\Core\Form\FormStateInterface; /** - * Implements hook_permission(). - */ -function form_test_permission() { - $perms = array( - 'access vertical_tab_test tabs' => array( - 'title' => t('Access vertical_tab_test tabs'), - ), - 'access autocomplete test' => array( - 'title' => t('Access autocomplete test'), - ), - ); - return $perms; -} - -/** * Implements hook_form_FORM_ID_alter() on behalf of block.module. */ function block_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) { diff --git a/core/modules/system/tests/modules/form_test/form_test.permissions.yml b/core/modules/system/tests/modules/form_test/form_test.permissions.yml new file mode 100644 index 0000000..f90e15e --- /dev/null +++ b/core/modules/system/tests/modules/form_test/form_test.permissions.yml @@ -0,0 +1,4 @@ +access vertical_tab_test tabs: + title: 'Access vertical_tab_test tabs' +access autocomplete test: + title: 'Access autocomplete test' diff --git a/core/modules/system/tests/modules/module_test/module_test.module b/core/modules/system/tests/modules/module_test/module_test.module index 522bab2..60d53ef 100644 --- a/core/modules/system/tests/modules/module_test/module_test.module +++ b/core/modules/system/tests/modules/module_test/module_test.module @@ -3,15 +3,6 @@ use Drupal\Core\Extension\Extension; /** - * Implements hook_permission(). - */ -function module_test_permission() { - return array( - 'module_test perm' => t('example perm for module_test module'), - ); -} - -/** * Implements hook_system_info_alter(). * * Manipulate module dependencies to test dependency chains. diff --git a/core/modules/system/tests/modules/module_test/module_test.permissions.yml b/core/modules/system/tests/modules/module_test/module_test.permissions.yml new file mode 100644 index 0000000..d5f5869 --- /dev/null +++ b/core/modules/system/tests/modules/module_test/module_test.permissions.yml @@ -0,0 +1,2 @@ +module_test perm: + title: 'example perm for module_test module' diff --git a/core/modules/system/tests/modules/router_test_directory/router_test.module b/core/modules/system/tests/modules/router_test_directory/router_test.module deleted file mode 100644 index ffbe070..0000000 --- a/core/modules/system/tests/modules/router_test_directory/router_test.module +++ /dev/null @@ -1,13 +0,0 @@ - array( - 'title' => t('Access test7 route'), - 'description' => t('Test permission only.'), - ), - ); -} diff --git a/core/modules/system/tests/modules/router_test_directory/router_test.permissions.yml b/core/modules/system/tests/modules/router_test_directory/router_test.permissions.yml new file mode 100644 index 0000000..0c61967 --- /dev/null +++ b/core/modules/system/tests/modules/router_test_directory/router_test.permissions.yml @@ -0,0 +1,3 @@ +access test7: + title: 'Access test7 route' + description: 'Test permission only.' diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 4701e26..f1361d5 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -96,11 +96,7 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) { * Implements hook_permission(). */ function taxonomy_permission() { - $permissions = array( - 'administer taxonomy' => array( - 'title' => t('Administer vocabularies and terms'), - ), - ); + $permissions = []; foreach (entity_load_multiple('taxonomy_vocabulary') as $vocabulary) { $permissions += array( 'edit terms in ' . $vocabulary->id() => array( diff --git a/core/modules/taxonomy/taxonomy.permissions.yml b/core/modules/taxonomy/taxonomy.permissions.yml new file mode 100644 index 0000000..a74d455 --- /dev/null +++ b/core/modules/taxonomy/taxonomy.permissions.yml @@ -0,0 +1,2 @@ +administer taxonomy: + title: 'Administer vocabularies and terms' diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 49e2530..07deb3c 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -34,17 +34,6 @@ function toolbar_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function toolbar_permission() { - return array( - 'access toolbar' => array( - 'title' => t('Use the administration toolbar'), - ), - ); -} - -/** * Implements hook_theme(). */ function toolbar_theme($existing, $type, $theme, $path) { diff --git a/core/modules/toolbar/toolbar.permissions.yml b/core/modules/toolbar/toolbar.permissions.yml new file mode 100644 index 0000000..54e73fb --- /dev/null +++ b/core/modules/toolbar/toolbar.permissions.yml @@ -0,0 +1,2 @@ +access toolbar: + title: 'Use the administration toolbar' diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index 001acaf..339454a 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -29,18 +29,6 @@ function tour_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_permission(). - */ -function tour_permission() { - return array( - 'access tour' => array( - 'title' => t('Access tour'), - 'description' => t('View tour tips.'), - ), - ); -} - -/** * Implements hook_toolbar(). */ function tour_toolbar() { diff --git a/core/modules/tour/tour.permissions.yml b/core/modules/tour/tour.permissions.yml new file mode 100644 index 0000000..fa14b8a --- /dev/null +++ b/core/modules/tour/tour.permissions.yml @@ -0,0 +1,3 @@ +access tour: + title: 'Access tour' + description: 'View tour tips.' diff --git a/core/modules/user/src/Plugin/views/access/Permission.php b/core/modules/user/src/Plugin/views/access/Permission.php index 490ff26..c79da2a 100644 --- a/core/modules/user/src/Plugin/views/access/Permission.php +++ b/core/modules/user/src/Plugin/views/access/Permission.php @@ -7,9 +7,12 @@ namespace Drupal\user\Plugin\views\access; +use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\user\PermissionHandlerInterface; use Drupal\views\Plugin\views\access\AccessPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; /** @@ -31,6 +34,41 @@ class Permission extends AccessPluginBase { protected $usesOptions = TRUE; /** + * The permission handler. + * + * @var \Drupal\user\PermissionHandlerInterface + */ + protected $permissionHandler; + + /** + * Constructs a Permission object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\user\PermissionHandlerInterface $permission_handler + * The permission handler. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler) { + $this->permissionHandler = $permission_handler; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('user.permissions') + ); + } + + /** * {@inheritdoc} */ public function access(AccountInterface $account) { @@ -63,19 +101,17 @@ protected function defineOptions() { public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); - $perms = array(); $module_info = system_get_info('module'); // Get list of permissions - foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) { - $permissions = \Drupal::moduleHandler()->invoke($module, 'permission'); - foreach ($permissions as $name => $perm) { - $perms[$module_info[$module]['name']][$name] = strip_tags($perm['title']); - } + $perms = []; + $permissions = $this->permissionHandler->getPermissions(); + foreach ($permissions as $perm => $perm_item) { + $provider = $perm_item['provider']; + $display_name = $module_info[$provider]['name']; + $perms[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title'])); } - ksort($perms); - $form['perm'] = array( '#type' => 'select', '#options' => $perms, diff --git a/core/modules/user/src/Plugin/views/filter/Permissions.php b/core/modules/user/src/Plugin/views/filter/Permissions.php index c0a651d..d3e7b50 100644 --- a/core/modules/user/src/Plugin/views/filter/Permissions.php +++ b/core/modules/user/src/Plugin/views/filter/Permissions.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\user\PermissionHandlerInterface; use Drupal\views\Plugin\views\filter\ManyToOne; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -22,11 +23,11 @@ class Permissions extends ManyToOne { /** - * The module handler. + * The permission handler. * - * @var \Drupal\Core\Extension\ModuleHandlerInterface + * @var \Drupal\user\PermissionHandlerInterface */ - protected $moduleHandler; + protected $permissionHandler; /** * Constructs a Permissions object. @@ -37,41 +38,36 @@ class Permissions extends ManyToOne { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. + * @param \Drupal\user\PermissionHandlerInterface $permission_handler + * The permission handler. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, PermissionHandlerInterface $permission_handler) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->moduleHandler = $module_handler; + $this->permissionHandler = $permission_handler; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($configuration, $plugin_id, $plugin_definition, $container->get('module_handler')); + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('user.permissions') + ); } public function getValueOptions() { if (!isset($this->value_options)) { $module_info = system_get_info('module'); - // Get a list of all the modules implementing a hook_permission() and sort by - // display name. - $modules = array(); - foreach ($this->moduleHandler->getImplementations('permission') as $module) { - $modules[$module] = $module_info[$module]['name']; - } - asort($modules); - - $this->value_options = array(); - foreach ($modules as $module => $display_name) { - if ($permissions = $this->moduleHandler->invoke($module, 'permission')) { - foreach ($permissions as $perm => $perm_item) { - $this->value_options[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title'])); - } - } + $permissions = $this->permissionHandler->getPermissions(); + foreach ($permissions as $perm => $perm_item) { + $provider = $perm_item['provider']; + $display_name = $module_info[$provider]['name']; + $this->value_options[$display_name][$perm] = String::checkPlain(strip_tags($perm_item['title'])); } } else { diff --git a/core/modules/user/src/Tests/Views/HandlerFilterPermissionTest.php b/core/modules/user/src/Tests/Views/HandlerFilterPermissionTest.php index 16db903..49af462 100644 --- a/core/modules/user/src/Tests/Views/HandlerFilterPermissionTest.php +++ b/core/modules/user/src/Tests/Views/HandlerFilterPermissionTest.php @@ -79,10 +79,16 @@ public function testFilterPermission() { // Test the value options. $value_options = $view->filter['permission']->getValueOptions(); + + $permisssion_by_module = []; + $permissions = \Drupal::service('user.permissions')->getPermissions(); + foreach ($permissions as $name => $permission) { + $permisssion_by_module[$permission['provider']][$name] = $permission; + } foreach (array('system' => 'System', 'user' => 'User') as $module => $title) { $expected = array_map(function ($permission) { return String::checkPlain(strip_tags($permission['title'])); - }, $this->container->get('module_handler')->invoke($module, 'permission')); + }, $permisssion_by_module[$module]); $this->assertEqual($expected, $value_options[$title], 'Ensure the all permissions are available'); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index e7afb5a..6ec3d98 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -438,33 +438,10 @@ function user_is_blocked($name) { */ function user_permission() { return array( - 'administer permissions' => array( - 'title' => t('Administer permissions'), - 'restrict access' => TRUE, - ), - 'administer account settings' => array( - 'title' => t('Administer account settings'), - 'description' => t('Configure site-wide settings and behavior for user accounts and registration.', array('@url' => url('admin/config/people'))), - 'restrict access' => TRUE, - ), - 'administer users' => array( - 'title' => t('Administer users'), - 'restrict access' => TRUE, - ), - 'access user profiles' => array( - 'title' => t('View user information'), - ), - 'change own username' => array( - 'title' => t('Change own username'), - ), 'cancel account' => array( 'title' => t('Cancel own user account'), 'description' => t('Note: content may be kept, unpublished, deleted or transferred to the %anonymous-name user depending on the configured user settings.', array('%anonymous-name' => \Drupal::config('user.settings')->get('anonymous'), '@user-settings-url' => url('admin/config/people/accounts'))), ), - 'select account cancellation method' => array( - 'title' => t('Select method for cancelling own account'), - 'restrict access' => TRUE, - ), ); } @@ -1213,14 +1190,13 @@ function user_role_load($rid) { * An associative array in the format $permission => $module. */ function user_permission_get_modules() { - $permissions = array(); - foreach (\Drupal::moduleHandler()->getImplementations('permission') as $module) { - $perms = \Drupal::moduleHandler()->invoke($module, 'permission'); - foreach ($perms as $key => $value) { - $permissions[$key] = $module; - } + $permissions = \Drupal::service('user.permissions')->getPermissions(); + $permissions_by_module = []; + foreach ($permissions as $name => $permission) { + $permissions_by_module[$name] = $permission['provider']; } - return $permissions; + + return $permissions_by_module; } /** @@ -1428,14 +1404,11 @@ function user_modules_installed($modules) { // Assign all available permissions to the administrator role. $rid = \Drupal::config('user.settings')->get('admin_role'); if ($rid) { - $permissions = array(); - foreach ($modules as $module) { - if ($module_permissions = \Drupal::moduleHandler()->invoke($module, 'permission')) { - $permissions = array_merge($permissions, array_keys($module_permissions)); - } - } + /** @var \Drupal\user\PermissionHandlerInterface $permission_handler */ + $permission_handler = \Drupal::service('user.permissions'); + $permissions = $permission_handler->getPermissions(); if (!empty($permissions)) { - user_role_grant_permissions($rid, $permissions); + user_role_grant_permissions($rid, array_keys($permissions)); } } } diff --git a/core/modules/user/user.permissions.yml b/core/modules/user/user.permissions.yml new file mode 100644 index 0000000..d84a362 --- /dev/null +++ b/core/modules/user/user.permissions.yml @@ -0,0 +1,17 @@ +administer permissions: + title: Administer permissions + restrict access: true +administer account settings: + title: 'Administer account settings' + description: 'Configure site-wide settings and behavior for user accounts and registration.' + restrict access: true +administer users: + title: 'Administer users' + restrict access: true +access user profiles: + title: 'View user information' +change own username: + title: 'Change own username' +select account cancellation method: + title: 'Select method for cancelling own account' + restrict access: true diff --git a/core/modules/views/tests/modules/views_test_data/views_test_data.module b/core/modules/views/tests/modules/views_test_data/views_test_data.module index 61c7fdb..1af309c 100644 --- a/core/modules/views/tests/modules/views_test_data/views_test_data.module +++ b/core/modules/views/tests/modules/views_test_data/views_test_data.module @@ -8,18 +8,6 @@ use Drupal\views\ViewExecutable; /** - * Implements hook_permission(). - */ -function views_test_data_permission() { - return array( - 'views_test_data test permission' => array( - 'title' => t('Test permission'), - 'description' => t('views_test_data test permission'), - ), - ); -} - -/** * Access callback for the generic handler test. * * @return bool diff --git a/core/modules/views/tests/modules/views_test_data/views_test_data.permissions.yml b/core/modules/views/tests/modules/views_test_data/views_test_data.permissions.yml new file mode 100644 index 0000000..ea742c7 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_data/views_test_data.permissions.yml @@ -0,0 +1,3 @@ +views_test_data test permission: + title: 'Test permission' + description: 'views_test_data test permission' diff --git a/core/modules/views/views.permissions.yml b/core/modules/views/views.permissions.yml index db47ea5..d2cafb3 100644 --- a/core/modules/views/views.permissions.yml +++ b/core/modules/views/views.permissions.yml @@ -1,4 +1,4 @@ -'access all views': +access all views: title: 'Bypass views access control' description: 'Bypass access control when accessing views.' - 'restrict access': TRUE + restrict access: TRUE diff --git a/core/modules/views_ui/views_ui.permissions.yml b/core/modules/views_ui/views_ui.permissions.yml index 0881aab..5d5f6ff 100644 --- a/core/modules/views_ui/views_ui.permissions.yml +++ b/core/modules/views_ui/views_ui.permissions.yml @@ -1,4 +1,4 @@ -'administer views': +administer views: title: 'Administer views' description: 'Access the views administration pages.' - 'restrict access': TRUE + restrict access: TRUE