You are here

function _purl_form_alter in Persistent URL 7

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

Private implementation of hook_form_alter()

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

File

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

Code

function _purl_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'menu_edit_menu') {

    //should this be the default value??
    if (isset($form['menu_name']['#default_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']['#default_value'], 'enabled'),
      );
      $form['purl']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
        '#submit' => array(
          'purl_menu_edit_submit',
        ),
      );
    }
  }
  elseif ($form_id == 'menu_edit_item') {

    // are these the options we wanted??
    $options = $form['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';
  }
  elseif ($form_id == 'redirect_edit_form') {

    // are these the options we wanted??
    $options = $form['redirect_options']['#value'];
    $form['purl'] = array(
      '#tree' => true,
      '#type' => 'fieldset',
      '#title' => t('Persistent URL'),
      '#weight' => -1,
    );

    // 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']['add'][0]) ? $options['purl']['add'][0]['provider'] . ':' . $options['purl']['add'][0]['id'] : '',
    );
    $form['#validate'][] = 'purl_redirect_edit_validate';
  }
}