You are here

function mass_contact_admin_edit in Mass Contact 7

Same name and namespace in other branches
  1. 5.2 mass_contact.module \mass_contact_admin_edit()
  2. 5 mass_contact.module \mass_contact_admin_edit()
  3. 6 mass_contact.module \mass_contact_admin_edit()

Displays a form to add or edit a category.

Parameters

array $form_state: A keyed array containing the current state of the form.

int $cid: The id of the category to edit. If NULL, then add rather than edit.

Return value

array An associative array that defines the form to be built.

1 string reference to 'mass_contact_admin_edit'
mass_contact_menu in ./mass_contact.module
Implements hook_menu().

File

./mass_contact.admin.inc, line 69
The administrative settings pages.

Code

function mass_contact_admin_edit(array $form, array $form_state, $cid = NULL) {

  // Initialize the array.
  $edit = array(
    'category' => '',
    'recipients' => '',
    'selected' => '',
    'cid' => '',
  );
  if (arg(4) == "edit" && $cid > 0) {

    // Get the information about the category being edited.
    $edit = db_select('mass_contact', 'mc')
      ->fields('mc')
      ->condition('cid', $cid)
      ->execute()
      ->fetchAssoc();
  }
  $form['category'] = array(
    '#type' => 'textfield',
    '#title' => t('Category'),
    '#maxlength' => 255,
    '#default_value' => $edit['category'],
    '#description' => t("Will appear in the subject of your email as [category]."),
    '#required' => TRUE,
  );
  $form['recipients'] = array(
    '#tree' => TRUE,
  );

  // Add form elements provided by grouping_method plugins.
  ctools_include('plugins');

  // Get the information about all plugins that implemnent this type of plugin.
  $plugins = ctools_get_plugins('mass_contact', 'grouping_method');
  foreach ($plugins as $plugin_name => $plugin) {

    // Get the admin edit function name for this particular implementation.
    $function = ctools_plugin_get_function($plugin, 'mass_contact_admin_edit');

    // Call the plugin function to add the form snippet(s).
    $form['recipients'][$plugin_name] = $function(unserialize($edit['recipients']));
  }
  $form['selected_categories'] = array(
    '#type' => 'fieldset',
    '#title' => t('Selected categories'),
  );
  $form['selected_categories']['selected'] = array(
    '#type' => 'select',
    '#title' => t('Selected'),
    '#options' => array(
      '0' => t('No'),
      '1' => t('Yes'),
    ),
    '#default_value' => $edit['selected'],
    '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
  );
  $form['selected_categories']['reset_selected'] = array(
    '#type' => 'checkbox',
    '#title' => t('Reset all previously selected categories to <em>No</em>'),
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $edit['cid'],
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}