You are here

function notifications_custom_form in Notifications 6

Same name and namespace in other branches
  1. 6.4 notifications_custom/notifications_custom.admin.inc \notifications_custom_form()

Edit / create custom subscriptions

2 string references to 'notifications_custom_form'
notifications_custom_admin_page in notifications_custom/notifications_custom.admin.inc
Page callback, administer custom subscriptions
notifications_custom_menu in notifications_custom/notifications_custom.module
Implementation of hook_menu().

File

notifications_custom/notifications_custom.admin.inc, line 47

Code

function notifications_custom_form($form_state, $subs) {
  $form['#subscription_type'] = $subs;
  $form['subscription'] = array(
    '#tree' => TRUE,
  );
  $form['subscription']['csid'] = array(
    '#type' => 'value',
    '#value' => $subs->csid,
  );
  $form['subscription']['type'] = array(
    '#type' => 'value',
    '#value' => $subs->type,
  );
  $form['subscription']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $subs->name,
    '#description' => t('Name for this subscription, only for administrative pages.'),
    '#required' => TRUE,
    '#weight' => -20,
  );

  // The type will be editable only if its a new subscription type, otherwise will be messy
  $editable = empty($subs->csid);
  $form['subscription']['newtype'] = array(
    '#title' => t('Subscription type'),
    '#type' => 'textfield',
    '#default_value' => $subs->type,
    '#required' => $editable,
    '#disabled' => !$editable,
    '#description' => t('The machine-readable name of this subscription type. This name must contain only lowercase letters, numbers, and underscores. This name must be unique and once created cannot be changed.'),
    '#weight' => -10,
  );
  $form['subscription']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $subs->title,
    '#description' => t('The title of the new subscription that will be shown to the user along with a subscribe checkbox.'),
    '#required' => TRUE,
    '#weight' => -5,
  );
  $event_types = notifications_module_information('event objects');
  $form['subscription']['event_type'] = array(
    '#title' => t('Event type'),
    '#type' => 'select',
    '#options' => $event_types,
    '#default_value' => $subs->event_type,
    '#description' => t('The type of events that will trigger this subscription.'),
  );
  if (!empty($subs->fields)) {
    foreach ($subs->fields as $data) {
      $format = notifications_format_subscription_field($data['type'], $data['value']);
      $rows[] = array(
        $format['name'],
        $format['value'],
      );
    }
    $form['subscription']['fields'] = array(
      '#type' => 'item',
      '#title' => t('Fields'),
      '#value' => theme('table', array(), $rows),
    );
  }
  $form['subscription']['explanation'] = array(
    '#type' => 'textarea',
    '#title' => t('Explanation'),
    '#default_value' => $subs->explanation,
    '#description' => t('An optional explanation to go with the subscription. The explanation will be shown to the user.'),
  );
  $form['subscription']['visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Visibility'),
    '#default_value' => $subs->visibility,
    '#options' => array(
      t('Hidden option, only accessible by administrators.'),
      t('User editable, will be shown to users.'),
    ),
  );
  $form['subscription']['register'] = array(
    '#type' => 'checkbox',
    '#title' => t('Visible in user registration form.'),
    '#default_value' => $subs->register,
  );
  $form['subscription']['default_value'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled for new users.'),
    '#default_value' => $subs->default_value,
    '#description' => t('If checked this subscription will be enabled by default for new users.'),
  );
  $form['subscription']['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $subs->weight,
    '#description' => t('The weights define the order in which the form fields are shown. Lighter fields "float up".'),
  );
  $form['buttons'] = array(
    '#type' => 'fieldset',
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($subs->module == 'notifications_custom') {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  else {
    $form['buttons']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
    );
  }
  return $form;
}