You are here

function simplenews_node_validate in Simplenews 7

Implements hook_node_validate().

File

./simplenews.module, line 391
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_node_validate($node, $form) {
  if (!simplenews_check_node_types($node->type)) {
    return;
  }

  // Check if a taxonomy term field is present in the node.
  $field = simplenews_get_category_field($node->type);
  if (!$field) {
    form_set_error('', t('No newsletter category field is configured. Check ... @todo'));
  }
  else {

    // Check if a newsletter category term is selected.
    $terms = simplenews_get_term_values($node);
    if (!$terms) {
      form_set_error($field['field_name'], t('A newsletter category term is required.'));
      watchdog('simplenews', '@todo ... newsletter taxonomy is required, change settings.', array(), WATCHDOG_ERROR);
    }
    elseif (count($terms) > 1) {
      form_set_error($field['field_name'], t('Only one newsletter category term is allowed.'));
      watchdog('simplenews', '@todo ... newsletter taxonomy must be single value, change settings.', array(), WATCHDOG_ERROR);
    }
  }
}