You are here

function sheetnode_node_validate in Sheetnode 7.2

Same name and namespace in other branches
  1. 7 sheetnode.module \sheetnode_node_validate()

Implements hook_node_validate().

Catch form errors to re-initialize sheetfields.

File

./sheetnode.module, line 692
Module file for the sheetnode module.

Code

function sheetnode_node_validate($node, $form, &$form_state) {
  $errors = form_get_errors();
  if (!empty($errors) && !empty($form_state['field'])) {
    foreach ($form_state['field'] as $field_name => $field) {
      if ($field[LANGUAGE_NONE]['field']['type'] == 'sheetfield' && !empty($form_state['input'][$field_name])) {
        foreach ($form_state['input'][$field_name][LANGUAGE_NONE] as $delta => $item) {
          $element_id = drupal_clean_css_identifier('edit-' . $field_name . '-' . LANGUAGE_NONE . '-' . $delta);
          $output = _sheetnode_inject(drupal_clean_css_identifier('sheetfield-' . $element_id), _sheetnode_sheetfield_aliases($field_name, $field[LANGUAGE_NONE]['instance']['label'], $item, $delta), $item['value'], $element_id, array(
            'entity-type' => 'node',
            'oid' => @$node->nid,
          ));
        }
      }
    }
  }
}