Guest User

Untitled

a guest
Jun 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /**
  2. * Implements hook_node_access().
  3. */
  4. function my_module_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Session\AccountInterface $account) {
  5. $state = $node->moderation_state->value;
  6. switch($op) {
  7. case 'update':
  8. if ($state !== 'draft') {
  9. if ($account->hasPermission('view any unpublished content')) {
  10. return AccessResult::allowed()->cachePerPermissions();
  11. }
  12. else {
  13. // Redirect to admin/content
  14. $url = Url::fromRoute("system.admin_content")->toString();
  15. $response = new RedirectResponse($url);
  16. $response->send();
  17. // Just in case author is trying something evil.
  18. return AccessResult::forbidden();
  19. }
  20. }
  21. break;
  22. default :
  23. return AccessResult::neutral();
  24. break;
  25. }
  26. }
Add Comment
Please, Sign In to add comment