You are here

function ad_ui_type_form in Advertisement 7.2

Form callback: create or edit a ad type.

1 string reference to 'ad_ui_type_form'
ad_ui_menu in ./ad_ui.module
Implements hook_menu().

File

includes/ad_ui.types.inc, line 65

Code

function ad_ui_type_form($form, &$form_state, $ad_type) {

  // Store the initial ad type in the form state.
  $form_state['ad_type'] = $ad_type;
  $form['ad_type'] = array(
    '#tree' => TRUE,
  );
  $form['ad_type']['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => $ad_type->name,
    '#description' => t('The human-readable name of this ad type. It is recommended that this name begin with a capital letter and contain only letters, numbers, and spaces. This name must be unique.'),
    '#required' => TRUE,
    '#size' => 32,
    '#field_suffix' => ' <small id="edit-ad-type-name-suffix">' . $ad_type->type . '</small>',
  );
  if (empty($ad_type->type)) {
    $js_settings = array(
      'type' => 'setting',
      'data' => array(
        'machineReadableValue' => array(
          'ad-type-name' => array(
            'text' => t('Machine name'),
            'target' => 'ad-type-type',
            'searchPattern' => '[^a-z0-9]+',
            'replaceToken' => '_',
          ),
        ),
      ),
    );
    $form['ad_type']['type'] = array(
      '#type' => 'textfield',
      '#title' => t('Machine name'),
      '#default_value' => $ad_type->type,
      '#maxlength' => 32,
      '#required' => TRUE,
      '#description' => t('The machine-readable name of this ad type. This name must contain only lowercase letters, numbers, and underscores, it must be unique.'),
      '#attached' => array(
        'js' => array(
          drupal_get_path('module', 'system') . '/system.js',
          $js_settings,
        ),
      ),
    );
  }
  $form['ad_type']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Describe this ad type. The text will be displayed on the <em>Add new content</em> page.'),
    '#default_value' => $ad_type->description,
    '#rows' => 3,
  );
  $form['ad_type']['help'] = array(
    '#type' => 'textarea',
    '#title' => t('Explanation or submission guidelines'),
    '#description' => t('This text will be displayed at the top of the page when creating or editing advertisements of this type.'),
    '#default_value' => $ad_type->help,
    '#rows' => 3,
  );
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save advertisement type'),
    '#weight' => 40,
  );
  if (!empty($ad_type->type)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete ad type'),
      '#suffix' => l('Cancel', 'admin/ad/types'),
      '#weight' => 45,
    );
  }
  else {
    $form['actions']['save_continue'] = array(
      '#type' => 'submit',
      '#value' => t('Save and add fields'),
      '#suffix' => l('Cancel', 'admin/ad/types'),
      '#weight' => 45,
    );
  }
  return $form;
}