You are here

function _purl_form_alter in Persistent URL 6

Same name and namespace in other branches
  1. 7 purl.admin.inc \_purl_form_alter()

Private implementation of hook_form_alter()

1 call to _purl_form_alter()
purl_form_alter in ./purl.module
Implementation of hook_form_alter.

File

./purl.admin.inc, line 176
Admin pages for the purl module.

Code

function _purl_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'menu_edit_menu') {
    if (isset($form['menu_name']['#value'])) {
      $form['purl'] = array(
        '#tree' => true,
        '#type' => 'fieldset',
        '#title' => t('Persistent URL behavior'),
        '#description' => t('All links are normally rewritten to contain the active persistent url elements. You may set all items in this menu to maintain existing modifications (the default), or to discard them.'),
      );
      $form['purl']['rewrite'] = array(
        '#type' => 'select',
        '#options' => array(
          'enabled' => t("Maintain"),
          'disabled' => "Discard",
        ),
        '#title' => t('Behavior'),
        '#default_value' => variable_get('purl_menu_behavior_' . $form['menu_name']['#value'], 'enabled'),
      );
      $form['purl']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
        '#submit' => array(
          'purl_menu_edit_submit',
        ),
      );
    }
  }
  elseif ($form_id == 'menu_edit_item') {
    $options = $form['menu']['options']['#value'];
    $form['purl'] = array(
      '#tree' => true,
      '#type' => 'fieldset',
      '#title' => t('Persistent URL'),
      '#weight' => -1,
    );
    $form['purl']['disabled'] = array(
      '#type' => 'select',
      '#options' => array(
        0 => t("Maintain"),
        1 => "Discard",
      ),
      '#title' => t('Behavior'),
      '#description' => t('All links are normally rewritten to contain the active persistent url elements. You may set this item to maintain existing modifications (the default), or to discard them.'),
      '#default_value' => isset($options['purl']) && isset($options['purl']['disabled']) ? $options['purl']['disabled'] : 0,
    );

    // Fetch all modifiers.
    $modifiers = array(
      '' => t('<none>'),
    );
    $methods = _purl_options();
    foreach (array_keys($methods) as $method) {
      foreach (purl_modifiers($method) as $value => $info) {
        $modifiers[$info['provider'] . ':' . $info['id']] = $value;
      }
    }
    asort($modifiers);
    $form['purl']['modifier'] = array(
      '#type' => 'select',
      '#options' => $modifiers,
      '#title' => t('Modifier'),
      '#description' => t('Enter a Persistent URL modifier to be used with this path.'),
      '#default_value' => isset($options['purl']) && isset($options['purl']['provider']) && isset($options['purl']['id']) ? $options['purl']['provider'] . ':' . $options['purl']['id'] : '',
    );
    $form['#validate'][] = 'purl_item_edit_validate';
    $form['#submit'][] = 'purl_item_edit_submit';
  }
}