You are here

function exclude_node_title_check_perm in Exclude Node Title 8

Same name and namespace in other branches
  1. 6 exclude_node_title.module \exclude_node_title_check_perm()
  2. 7 exclude_node_title.module \exclude_node_title_check_perm()

Check permission to change node title exclusion.

Parameters

\Drupal\node\NodeInterface $node: The node that is being inserted or updated.

Return value

bool Returns TRUE if the current user may exclude this node's title.

5 calls to exclude_node_title_check_perm()
exclude_node_title_form_alter in ./exclude_node_title.module
Implements hook_form_alter().
exclude_node_title_node_insert in ./exclude_node_title.module
Implements hook_node_insert().
exclude_node_title_node_update in ./exclude_node_title.module
Implements hook_node_update().
exclude_node_title_preprocess_page in ./exclude_node_title.module
Implements hook_preprocess_page().
exclude_node_title_preprocess_page_title in ./exclude_node_title.module
Implements hook_preprocess_page_title().

File

./exclude_node_title.module, line 219
Primarily Drupal hooks and global API functions to exclude node titles.

Code

function exclude_node_title_check_perm(NodeInterface $node) {
  $user = \Drupal::currentUser();
  if ($user
    ->hasPermission('exclude any node title')) {
    return TRUE;
  }
  if ($user
    ->hasPermission('exclude own node title') && $user
    ->id() == $node
    ->getOwnerId()) {
    return TRUE;
  }
  return FALSE;
}