You are here

function serial_form_alter in Serial Field 6

Implementation of hook_form_alter().

File

./serial.module, line 64
The Serial module main file.

Code

function serial_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'content_field_edit_form' && $form['#field']['type'] == 'serial') {

    // Hide irrelevant settings:
    unset($form['widget']);
    unset($form['field']);

    // After creation of a new field:
    if (preg_match('#^.*destination.*\\=(.*)$#', $form['#action'], $matches)) {

      // Set serial values for old objects
      module_load_include('inc', 'serial');
      $field = $form['#field'];
      $old_count = _serial_init_old_nodes($field);

      // (field is not ready yet at serial_content_fieldapi's 'create instance')
      // Show messages:
      drupal_set_message(t('Serial field %field has been created.', array(
        '%field' => $field['field_name'],
      )));
      if ($old_count) {
        drupal_set_message(t('Serial values have been automatically set for %count existing nodes.', array(
          '%count' => $old_count,
        )));
      }

      // Go back to Managed Fields:
      drupal_goto(urldecode($matches[1]));
    }
  }
}