You are here

function maxlength_nodeapi in Maxlength 5.2

Same name and namespace in other branches
  1. 5 maxlength.module \maxlength_nodeapi()
  2. 6 maxlength.module \maxlength_nodeapi()

Implementation of hook_nodeapi().

File

./maxlength.module, line 246

Code

function maxlength_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  $fields = array(
    'title',
    'body',
  );
  foreach ($fields as $field) {
    $limit = intval(variable_get(MAXLENGTH_NODE_TYPE . $field . '_' . $node->type, ''));
    if ($limit > 0) {
      switch ($op) {
        case 'validate':
          $form = $a3;
          if (drupal_strlen($node->{$field}) > $limit) {
            form_set_error($field, t('The !field field has exceeded its maximum number of characters (!limit).', array(
              '!limit' => $limit,
              '!field' => $field,
            )));
          }
          break;
      }
    }
  }
}