function like_and_dislike_permission in Like & Dislike 7
Implementing hook_permission()
Defines view and vote permissions for every content type and a management permission
File
- ./
like_and_dislike.module, line 27
Code
function like_and_dislike_permission() {
$perms = array();
// Administrative
$perms['manage like dislike'] = array(
'title' => t('Manage Like/DisLike options'),
'description' => t('Manage administrative options of the like/dislike module.'),
'restrict access' => TRUE,
);
// End users
$entity_types = entity_get_info();
foreach ($entity_types as $type_name => $type_info) {
if (!in_array($type_name, Drupal\like_and_dislike\Model\Entity::$available_entity_types)) {
continue;
}
switch ($type_name) {
case 'node':
foreach ($type_info['bundles'] as $bundle_name => $bundle) {
$perms['like/dislike any ' . $bundle_name . ' nodes'] = array(
'title' => t('Add like/dislike to any %type', array(
'%type' => $bundle['label'],
)),
'description' => t('Allow users to Like/Dislike nodes from %type content type.', array(
'%type' => $bundle['label'],
)),
'restrict access' => TRUE,
);
$perms['view likes/dislikes from every ' . $bundle_name . ' nodes'] = array(
'title' => t('View likes/dislikes from every %type', array(
'%type' => $bundle['label'],
)),
'description' => t('Allow users to view Likes/Dislikes from entities of type %type.', array(
'%type' => $bundle['label'],
)),
'restrict access' => TRUE,
);
}
break;
case 'comment':
foreach ($type_info['bundles'] as $bundle_name => $bundle) {
$perms['like/dislike any ' . $bundle_name . ' comments'] = array(
'title' => t('Add like/dislike to any %type', array(
'%type' => $bundle['label'],
)),
'description' => t('Allow users to Like/Dislike entities from %type content type.', array(
'%type' => $bundle['label'],
)),
'restrict access' => TRUE,
);
$perms['view likes/dislikes from every ' . $bundle_name . ' comments'] = array(
'title' => t('View likes/dislikes from every %type', array(
'%type' => $bundle['label'],
)),
'description' => t('Allow users to view Likes/Dislikes from entities of type %type.', array(
'%type' => $bundle['label'],
)),
'restrict access' => TRUE,
);
}
break;
}
}
return $perms;
}