Commit 52a101bc authored by alexpott's avatar alexpott

Issue #2328411 by dawehner, geerlingguy, herom: Convert all permissions to yml...

Issue #2328411 by dawehner, geerlingguy, herom: Convert all permissions to yml files and permission callbacks.
parent 966aed8f
......@@ -34,17 +34,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().
*/
......
administer actions:
title: 'Administer actions'
......@@ -92,20 +92,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().
*
......
administer news feeds:
title: 'Administer news feeds'
access news feeds:
title: 'View news feeds'
......@@ -27,14 +27,3 @@ function ban_help($route_name, RouteMatchInterface $route_match) {
return '<p>' . 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.') . '</p>';
}
}
/**
* Implements hook_permission().
*/
function ban_permission() {
return array(
'ban IP addresses' => array(
'title' => t('Ban IP addresses'),
),
);
}
ban IP addresses:
title: 'Ban IP addresses'
......@@ -62,17 +62,6 @@ function block_theme() {
);
}
/**
* Implements hook_permission().
*/
function block_permission() {
return array(
'administer blocks' => array(
'title' => t('Administer blocks'),
),
);
}
/**
* Implements hook_page_build().
*
......
administer blocks:
title: 'Administer blocks'
......@@ -82,27 +82,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().
*/
......
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.'
......@@ -197,33 +197,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().
*/
......
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'
......@@ -27,25 +27,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().
*/
......
synchronize configuration:
title: 'Synchronize configuration'
restrict access: true
export configuration:
title: 'Export configuration'
restrict access: true
import configuration:
title: 'Import configuration'
restrict access: true
......@@ -36,18 +36,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().
*/
......
translate configuration:
title: 'Translate user edited configuration'
description: 'Translate any configuration not shipped with modules and themes.'
......@@ -38,23 +38,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().
*/
......
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'
......@@ -360,61 +360,6 @@ function content_translation_access(EntityInterface $entity, $op) {
return content_translation_controller($entity->getEntityTypeId())->getTranslationAccess($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'),
),
);
// Create a translate permission for each enabled entity type and (optionally)
// bundle.
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($permission_granularity = $entity_type->getPermissionGranularity()) {
$t_args = array('@entity_label' => $entity_type->getLowercaseLabel());
switch ($permission_granularity) {
case 'bundle':
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
if (content_translation_enabled($entity_type_id, $bundle)) {
$t_args['%bundle_label'] = isset($bundle_info['label']) ? $bundle_info['label'] : $bundle;
$permission["translate $bundle $entity_type_id"] = array(
'title' => t('Translate %bundle_label @entity_label', $t_args),
);
}
}
break;
case 'entity_type':
if (content_translation_enabled($entity_type_id)) {
$permission["translate $entity_type_id"] = array(
'title' => t('Translate @entity_label', $t_args),
);
}
break;
}
}
}
return $permission;
}
/**
* Implements hook_form_alter().
*/
......
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'
permission_callbacks:
- \Drupal\content_translation\ContentTranslationPermissions::contentPermissions
<?php
/**
* @file
* Contains \Drupal\content_translation\ContentTranslationPermissions.
*/
namespace Drupal\content_translation;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides dynamic permissions for the content_translation module.
*/
class ContentTranslationPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a ContentTranslationPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity.manager'));
}
/**
* Returns an array of content translation permissions.
*
* @return array
*/
public function contentPermissions() {
$permission = [];
// Create a translate permission for each enabled entity type and (optionally)
// bundle.
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($permission_granularity = $entity_type->getPermissionGranularity()) {
$t_args = ['@entity_label' => $entity_type->getLowercaseLabel()];
switch ($permission_granularity) {
case 'bundle':
foreach ($this->entityManager->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
if (content_translation_enabled($entity_type_id, $bundle)) {
$t_args['%bundle_label'] = isset($bundle_info['label']) ? $bundle_info['label'] : $bundle;
$permission["translate $bundle $entity_type_id"] = [
'title' => $this->t('Translate %bundle_label @entity_label', $t_args),
];
}
}
break;
case 'entity_type':
if (content_translation_enabled($entity_type_id)) {
$permission["translate $entity_type_id"] = [
'title' => $this->t('Translate @entity_label', $t_args),
];
}
break;
}
}
}
return $permission;
}
}
......@@ -86,18 +86,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().
*/
......
access contextual links:
title: 'Use contextual links'
description: 'Use contextual links to perform actions related to elements on a page.'
administer display modes:
title: 'Add, edit, and delete custom display modes.'
......@@ -20,23 +20,6 @@
require_once __DIR__ . '/field_test.entity.inc';
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.
*
......
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'
......@@ -59,36 +59,6 @@ function field_ui_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
* Implements hook_permission().
*/
function field_ui_permission() {
$permissions = array();
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->isFieldable()) {
// Create a permission for each fieldable entity to manage
// the fields and the display.
$permissions['administer ' . $entity_type_id . ' fields'] = array(
'title' => t('%entity_label: Administer fields', array('%entity_label' => $entity_type->getLabel())),
'restrict access' => TRUE,
);
$permissions['administer ' . $entity_type_id . ' form display'] = array(
'title' => t('%entity_label: Administer form display', array('%entity_label' => $entity_type->getLabel()))
);
$permissions['administer ' . $entity_type_id . ' display'] = array(
'title' => t('%entity_label: Administer display', array('%entity_label' => $entity_type->getLabel()))
);
}
}
$permissions['administer display modes'] = array(
'title' => t('Add, edit, and delete custom display modes.'),
);
return $permissions;
}
/**
* Implements hook_theme().
*/
......
administer display modes:
title: 'Add, edit, and delete custom display modes.'
permission_callbacks:
- Drupal\field_ui\FieldUiPermissions::fieldPermissions
<?php
/**
* @file
* Contains \Drupal\field_ui\FieldUiPermissions.
*/
namespace Drupal\field_ui;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides dynamic permissions of the field_ui module.
*/
class FieldUiPermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a new FieldUiPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity.manager'));
}
/**
* Returns an array of field UI permissions.
*
* @return array
*/
public function fieldPermissions() {
$permissions = [];
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->isFieldable()) {
// Create a permission for each fieldable entity to manage
// the fields and the display.
$permissions['administer ' . $entity_type_id . ' fields'] = [
'title' => $this->t('%entity_label: Administer fields', ['%entity_label' => $entity_type->getLabel()]),
'restrict access' => TRUE,
];
$permissions['administer ' . $entity_type_id . ' form display'] = [
'title' => $this->t('%entity_label: Administer form display', ['%entity_label' => $entity_type->getLabel()])
];
$permissions['administer ' . $entity_type_id . ' display'] = [
'title' => $this->t('%entity_label: Administer display', ['%entity_label' => $entity_type->getLabel()])
];
}
}
return $permissions;
}
}
......@@ -1889,20 +1889,6 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
return $return;
}
/**
* 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 <a href="!url">all files</a>.', array('!url' => url('admin/content/files'))),
),
);
return $perms;
}
/**
* Formats human-readable version of file status.
*
......
access files overview:
title: 'Access the Files overview page'
description: 'Get an overview of all files.'
......@@ -224,32 +224,6 @@ function filter_pre_render_text(array $element) {
return $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 <a href="@url">text formats</a>.', array(
'@url' => url('admin/config/content/formats'),
)),
'restrict access' => TRUE,
);
// Generate permissions for each text format. Warn the administrator that any
// of them are potentially unsafe.
foreach (filter_formats() as $format) {
if ($permission = $format->getPermissionName()) {
$format_name_replacement = l($format->label(), 'admin/config/content/formats/manage/' . $format->id());
$perms[$permission] = array(
'title' => t("Use the !text_format text format", array('!text_format' => $format_name_replacement,)),
'description' => String::placeholder(t('Warning: This permission may have security implications depending on how the text format is configured.')),
);
}
}
return $perms;
}
/**
* Retrieves a list of enabled text formats, ordered by weight.
*
......
administer filters:
title: 'Administer text formats and filters'
description: 'Define how text is handled by combining filters into text formats.'