You are here

function extlink_extra_form_extlink_admin_settings_alter in External Links Extra 7

Same name and namespace in other branches
  1. 8 extlink_extra.module \extlink_extra_form_extlink_admin_settings_alter()

Implementation of hook_form_FORM_ID_alter().

File

./extlink_extra.module, line 124
This module adds some extra functionality to the External Links module.

Code

function extlink_extra_form_extlink_admin_settings_alter(&$form, &$form_state) {

  // Provide an option for which type of external link warning.
  $form['extlink_alert_type'] = array(
    '#type' => 'select',
    '#title' => t('When external links are clicked'),
    '#default_value' => variable_get('extlink_alert_type', 'colorbox'),
    '#options' => array(
      '' => t('Don\'t display a warning message'),
      'confirm' => t('Warn with a confirmation popup'),
      'page' => t('Warn on a separate page'),
    ),
  );
  if (module_exists('colorbox')) {
    $form['extlink_alert_type']['#options']['colorbox'] = t('Warn using a modal dialog (colorbox)');
  }

  // Make a fieldset to put our new stuff in.
  $form['extlink_alert_text_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => 'Warning Text',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#states' => array(
      'invisible' => array(
        ':input[name=extlink_alert_type]' => array(
          'value' => '',
        ),
      ),
    ),
  );
  $form['extlink_alert_text_fieldset']['extlink_page_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Page Title'),
    '#description' => t('Specify the page title when you warn using a page. Available tokens are listed below.'),
    '#default_value' => variable_get('extlink_page_title', NULL),
    '#states' => array(
      'visible' => array(
        ':input[name=extlink_alert_type]' => array(
          'value' => 'page',
        ),
      ),
    ),
  );
  $eat_default = variable_get('extlink_alert_text', array(
    'value' => extlink_extra_alert_default(),
    'format' => filter_default_format(),
  ));

  // This form component is inherited from extlink.
  $form['extlink_alert_text']['#type'] = 'text_format';
  $form['extlink_alert_text']['#title'] = 'Text';
  $form['extlink_alert_text']['#description'] = 'The text to use for the confirm, colorbox, or page.  If using colorbox or page, this can be blank and you can use the tpl instead.';
  $form['extlink_alert_text']['#default_value'] = $eat_default['value'];
  $form['extlink_alert_text']['#format'] = $eat_default['format'];
  $form['extlink_alert_text']['#rows'] = 16;

  // Show a token tree with suggestions to use extlink tokens.
  $form['extlink_alert_text_fieldset']['token_help'] = array(
    '#theme' => 'token_tree',
    '#global_types' => TRUE,
    '#click_insert' => TRUE,
    '#weight' => 20,
    '#token_types' => array(
      'extlink',
    ),
  );

  // @todo - Need comment to understand this code
  if (isset($form['extlink_alert_text']['#wysiwyg']) && !$form['extlink_alert_text']['#wysiwyg']) {
    $form['extlink_alert_text_fieldset']['#attributes']['class'][] = 'alert-text-wysiwyg-disabled';
    $form['extlink_alert_text_fieldset']['#attached']['css'][] = drupal_get_path('module', 'extlink_extra') . '/extlink_extra.admin.css';
  }

  // Move the old alert text field into the fieldset.
  $form['extlink_alert_text_fieldset']['extlink_alert_text'] = $form['extlink_alert_text'];

  // Get rid of the old field since we moved it into the fieldset.
  unset($form['extlink_alert_text']);

  // Remove the 'Display pop-up warnings' checkbox that extlink.module provides.
  $form['extlink_alert']['#access'] = FALSE;
  $form['extlink_alert_timer'] = array(
    '#type' => 'textfield',
    '#title' => t('Redirect timer'),
    '#default_value' => variable_get('extlink_alert_timer', 0),
    '#description' => t('Enter the number of seconds you want to delay redirection after a user clicks on an external link.  Enter 0 to disable the timer.  Using this feature will not allow the link to open in a new window.'),
  );
  $form['extlink_cache_fix'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable aggressive caching compatibility'),
    '#description' => t('If you\'re running an aggressive caching system like varnish or memcached, you may find that the \'now-leaving\' page or colorbox popup gets cached
     and shows the same redirect tokens for all users.  Enabling this option will cause the module to overcome this by using client side (javascript) code to dynamically
     replace the values when the page is loaded.  <br/>
     <span class="error">Note</span> that this depends on your links being wrapped in the default classes: extlink-extra-back-action and extlink-extra-go-action.
     See extlink-extra-leaving-tpl.example.php for an example.'),
    '#default_value' => variable_get('extlink_cache_fix', 0),
  );
  $form['extlink_508'] = array(
    '#type' => 'fieldset',
    '#title' => 'Section 508 Accessibility',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['extlink_508']['extlink_508_fix'] = array(
    '#type' => 'checkbox',
    '#title' => t('Section 508 improvement for link indicators'),
    '#description' => t('Improves usability for screen readers by adding offscreen text to the span tags created by the External Link module.'),
    '#default_value' => variable_get('extlink_508_fix', 0),
  );
  $form['extlink_508']['extlink_508_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Section 508 text'),
    '#description' => t('Screenreader text used when 508 fix is applied'),
    '#default_value' => variable_get('extlink_508_text', EXTLINK_EXTRA_508_TEXT),
    '#states' => array(
      'invisible' => array(
        ':input[name=extlink_508_fix]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $form['extlink_url_override'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow url parameters to set destination and back links'),
    '#description' => t('If you have advertisements and require a bumper for leaving the site, some advertisers use url parameters to set the destination.
     Select this checkbox to allow url parameters to set the destination and back links. Links must be prepended with http://.<br/>
     Eg. example.com/now-leaving?external_url=http://newurl.com&back_url=http://example.com/old-path.'),
    '#default_value' => variable_get('extlink_url_override', 0),
  );
  $form['patterns']['#weight'] = 1;
  $form['patterns']['extlink_exclude_warning'] = array(
    '#title' => t("Don't warn for links matching the pattern"),
    '#description' => t('Enter a regular expression for external links that you wish <strong>not</strong> to display a warning when clicked'),
    '#type' => 'textfield',
    '#default_value' => variable_get('extlink_exclude_warning', ''),
  );
}