You are here

function purge_item_form_validate in Purge 7.2

Form validation for the item form.

File

includes/purge_ui.inc, line 470
Provides administrative interface for the Purge module.

Code

function purge_item_form_validate($form, &$form_state) {
  $errors = array();

  // First get the item with the form state
  $bundle = purge_item_form_load($form, $form_state);

  // First validate the item.
  $item_type = $form_state['values']['item_type'];
  $item_name = $form_state['values']['machine_name'];
  $item = $bundle->{$item_type}[$item_name];

  // Validate if needed.
  if ($item instanceof PurgeValidateable) {
    $errors = $item
      ->validate();
    if (count($errors) == 0) {

      // Validate the bundle.
      // $errors = $bundle->validate();
    }

    // Now set a form error.
    if (count($errors) > 0) {
      foreach ($errors as $error) {

        // Display the errors
        form_set_error($error['name'], $error['message']);
      }
    }
    else {

      // Check if we're being triggered by the validate butten.
      if ($form_state['clicked_button']['#type'] == 'button') {
        $form_state['rebuild'] == FALSE;
        drupal_set_message(t('@item_type @item_name validated correctly.', array(
          '@item_type' => $bundle->type[$item_type]->name,
          '@item_name' => $form_state['values']['name'],
        )));
      }
    }
  }
  return $form;
}