I'm running in to a problem with my drupal 8 site. I want to give access to unpublished content. I found a solution using a hook.
I want to create a custom module these don't seem to work.
I found this for the unpublished problem: "View unpublished content" permission for non-author
It looks like a solid solutions for my problems but I can't get them to work. I can enable the modules created, and it doesn't give any errors.
My view_unpub.info.yml file:
name: View Unpublished
type: module
description: 'View Unpublished Content'
package: SVDS
core: 8.x
My view_unpub.module file:
<?php
function view_unpub_permission()
{
return array(
'unconditionally view unpublished content' => array(
'title' => t('Unconditionally View Unpublished Content'),
'restrict access' => TRUE
)
);
}
function view_unpub_node_access($node, $op, $account)
{
// We're only bothered about the 'view' operation at the moment
if ($op == 'view') {
// If the user has access to our new permission, let 'em at it
if (user_access('unconditionally view unpublished content', $account)) {
return NODE_ACCESS_ALLOW;
}
}
// For everything else let the system decide.
return NODE_ACCESS_IGNORE;
}
hook_permission
no longer exists in Drupal 8. You need to add a mymodule.permissions.yml file, which is the new way. See: aram.cz/article/custom-permissions-drupal-8