You are here

function node_limit_limits in Node Limit 8

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

Returns all the limits that can be applied to a specific node.

Parameters

object $node: The node object that may be limited.

1 call to node_limit_limits()
_node_limit_violates_limit in old/node_limit.module
Helper function to check limit violations for this node.

File

old/node_limit.module, line 276

Code

function node_limit_limits(&$node) {
  $user = \Drupal::service('entity_type.manager')
    ->getStorage('user')
    ->load($node->uid);

  // Get all the limits.
  $query = \Drupal::database()
    ->select('node_limit', 'nl')
    ->fields('nl')
    ->orderBy('weight', 'ASC')
    ->execute();
  $applicable_limits = array();
  foreach ($query as $row) {

    // This particular limit id.
    $lid = $row->lid;
    $applies = TRUE;
    $submodule_applies = module_invoke_all('node_limit_applies_in_context', $lid, $node, $user);
    foreach ($submodule_applies as $module => $module_applies) {

      // A submodule returns DOESNT_APPLY if it requires a specific user or role, etc,
      // and the context given does not satisfy that.
      if ($module_applies == NODE_LIMIT_LIMIT_DOESNT_APPLY) {
        $applies = FALSE;
      }
    }
    if ($applies == TRUE) {
      $applicable_limits[] = $lid;
    }
  }
  return $applicable_limits;
}