You are here

function biblio_save_node_validate in Bibliography Module 7

Same name and namespace in other branches
  1. 7.2 includes/biblio.import.export.inc \biblio_save_node_validate()
1 call to biblio_save_node_validate()
biblio_save_node in includes/biblio.import.export.inc

File

includes/biblio.import.export.inc, line 664
Functions that are used to import and export biblio data.

Code

function biblio_save_node_validate($node) {
  static $schema = array();
  $error = array();
  if (empty($schema)) {
    $schema['biblio'] = drupal_get_schema('biblio');
  }
  if (isset($node->title) && strlen($node->title) > 255) {
    $error['title'] = $node->title;
    $node->title = substr($node->title, 0, 255);
  }
  if (isset($node->biblio_keywords) && is_array($node->biblio_keywords)) {
    foreach ($node->biblio_keywords as $key => $word) {
      if (strlen($word) > 255) {
        $error['keyword'] = $word;
        $node->biblio_keywords[$key] = substr($word, 0, 255);
      }
    }
  }
  if (isset($node->biblio_contributors) && is_array($node->biblio_contributors)) {
    foreach ($node->biblio_contributors as $key => $author) {
      if (strlen($author['name']) > 255) {
        $error['author'] = $author['name'];
        $node->biblio_contributors[$key]['name'] = substr($author['name'], 0, 255);
      }
    }
  }
  foreach ($schema['biblio']['fields'] as $field => $spec) {
    if (isset($node->{$field})) {
      switch ($spec['type']) {
        case 'varchar':
          if (strlen($node->{$field}) > $spec['length']) {
            $error[$field] = $node->{$field};
            $node->{$field} = substr($node->{$field}, 0, $spec['length']);
          }
          break;
      }
    }
  }
  return $error;
}