You are here

function hook_node_limit_element_validate in Node Limit 8

Same name and namespace in other branches
  1. 7 node_limit.api.php \hook_node_limit_element_validate()

Validate a submodules' elements values.

Called when the user attempts to add or edit a Node Limit. The implementor of the hook has the opportunity to validate the value the user entered.

Parameters

object $element: The element.

Return value

array TODO explain

5 functions implement hook_node_limit_element_validate()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

node_limit_interval_node_limit_element_validate in old/node_limit_interval/node_limit_interval.module
Implements hook_node_limit_element_validate().
node_limit_role_node_limit_element_validate in old/node_limit_role/node_limit_role.module
Implements hook_node_limit_element_validate().
node_limit_type_node_limit_element_validate in old/node_limit_type/node_limit_type.module
Implements hook_node_limit_element_validate().
node_limit_userofrole_node_limit_element_validate in old/node_limit_userofrole/node_limit_userofrole.module
Implements hook_node_limit_element_validate().
node_limit_user_node_limit_element_validate in old/node_limit_user/node_limit_user.module
Implements hook_node_limit_element_validate().
1 invocation of hook_node_limit_element_validate()
node_limit_limit_form_validate in old/node_limit.module
Validation hook for node_limit_limit_form.

File

old/node_limit.api.php, line 97
Node_limit api reference.

Code

function hook_node_limit_element_validate($element) {

  /*
   * Validation:
   * User cannot be user:1
   * User must be in the {user} table.
   */
  $potential_user = user_load_by_name($element);
  if ($potential_user->uid == 1) {

    // We cannot apply a limit to user:1.
    return array(
      'error' => t('Node Limits cannot be applied to User #1'),
    );
  }
  elseif ($potential_user === FALSE) {

    // Unknown user.
    return array(
      'error' => t('Unknown user "!user"', array(
        '!user' => $element,
      )),
    );
  }
  return TRUE;
}