You are here

function notifications_custom_form in Notifications 6.4

Same name and namespace in other branches
  1. 6 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 51
Custom notifications module (admin features)

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']['module'] = array(
    '#type' => 'value',
    '#value' => !empty($subs->module) ? $subs->module : 'notifications_custom',
  );
  $form['subscription']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $subs->title,
    '#description' => t('User readable name for this subscription type.'),
    '#required' => TRUE,
    '#weight' => -5,
  );

  // 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.'),
  );
  $form['subscription']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $subs->name,
    '#description' => t('The title of the new subscription that will be shown to the user along with a subscribe checkbox.'),
    '#required' => TRUE,
  );
  $form['subscription']['event_type'] = array(
    '#title' => t('Event type'),
    '#type' => 'select',
    '#options' => notifications_info('event classes'),
    '#default_value' => $subs->event_type,
    '#description' => t('The type of events that will trigger this subscription.'),
  );
  if (!empty($subs->fields)) {
    $form['subscription']['fields'] = array(
      '#type' => 'item',
      '#title' => t('Fields'),
      '#value' => notifications_build_subscription($subs)
        ->format_fields(Notifications_Subscription::FORMAT_TABLE),
    );
  }
  $form['subscription']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Explanation'),
    '#default_value' => $subs->description,
    '#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']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
    );
  }
  else {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }
  return $form;
}