You are here

function quicklink_config_form in Quicklink 7

Page callback: Configuration form to update module settings.

1 string reference to 'quicklink_config_form'
quicklink_menu in ./quicklink.module
Implements hook_menu().

File

./quicklink.module, line 28

Code

function quicklink_config_form($form, &$form_state) {
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
    '#attributes' => array(
      'class' => array(
        'quicklink',
      ),
    ),
  );

  // Ignore tab.
  $form['ignore'] = array(
    '#type' => 'fieldset',
    '#title' => t('Prefetch Ignore Settings'),
    '#description' => t('On this tab, specify what Quicklink should not prefetch.'),
    '#group' => 'settings',
  );
  $form['ignore']['quicklink_ignore_admin_paths'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not prefetch admin paths'),
    '#description' => t('Highly recommended. Ignore administrative paths.'),
    '#default_value' => variable_get('quicklink_ignore_admin_paths', 1),
  );
  $form['ignore']['quicklink_ignore_ajax_links'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not prefetch AJAX links'),
    '#description' => t('Highly recommended. Ignore links that trigger AJAX behavior.'),
    '#default_value' => variable_get('quicklink_ignore_ajax_links', 1),
  );
  $form['ignore']['quicklink_ignore_hashes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore paths with hashes (#) in them'),
    '#description' => t('Recommended. Prevents multiple prefetches of the same page.'),
    '#default_value' => variable_get('quicklink_ignore_hashes', 1),
  );
  $form['ignore']['quicklink_ignore_file_ext'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore paths with file extensions'),
    '#description' => t('Recommended. This will ignore links that end with a file extension.
      It will match paths ending with a period followed by 1-5 characters. Querystrings are supported.'),
    '#default_value' => variable_get('quicklink_ignore_file_ext', 1),
  );
  $form['ignore']['quicklink_url_patterns_to_ignore'] = array(
    '#type' => 'textarea',
    '#title' => t('URL patterns to ignore (optional)'),
    '#description' => t('Quicklink will not fetch data if the URL contains any of these patterns. One per line.'),
    '#default_value' => variable_get('quicklink_url_patterns_to_ignore', ''),
    '#resizable' => FALSE,
    '#attributes' => array(
      'style' => 'max-width: 600px;',
    ),
  );

  // Overrides tab.
  $form['overrides'] = array(
    '#type' => 'fieldset',
    '#title' => t('Optional Overrides'),
    '#description' => t('On this tab, specify various overrides.'),
    '#group' => 'settings',
  );
  $form['overrides']['quicklink_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('Override parent selector (optional)'),
    '#description' => t('Quicklink will search this CSS selector for URLs to prefetch (ex. <code>.body-inner</code>). Defaults to the whole document.'),
    '#maxlength' => 128,
    '#size' => 128,
    '#default_value' => variable_get('quicklink_selector', ''),
    '#attributes' => array(
      'style' => 'max-width: 600px;',
    ),
  );
  $form['overrides']['quicklink_allowed_domains'] = array(
    '#type' => 'textarea',
    '#title' => t('Override allowed domains (optional)'),
    '#description' => t('List of domains to prefetch from. If empty, Quicklink will only prefetch links from the origin domain.
      If you configure this, be sure to input the origin domain. Add <code>true</code> here to allow <em>every</em> origin.'),
    '#default_value' => variable_get('quicklink_allowed_domains', ''),
    '#resizable' => FALSE,
    '#attributes' => array(
      'style' => 'max-width: 600px;',
    ),
  );
  $form['overrides']['quicklink_prefetch_only_paths'] = array(
    '#type' => 'textarea',
    '#title' => t('Prefetch these paths only (overrides everything else)'),
    '#description' => t('If enabled, will override other settings. <strong>Only these paths will be prefetched.</strong> Include the forward slash at the beginning of the path.'),
    '#default_value' => variable_get('quicklink_prefetch_only_paths', ''),
    '#resizable' => FALSE,
    '#attributes' => array(
      'style' => 'max-width: 600px;',
    ),
  );

  // When to Prefetch tab.
  $form['when_load_library'] = array(
    '#type' => 'fieldset',
    '#title' => t('When to Load Library'),
    '#description' => t('On this tab, specify when the Quicklink library will be loaded.'),
    '#group' => 'settings',
  );
  $form['when_load_library']['quicklink_no_load_when_authenticated'] = array(
    '#type' => 'checkbox',
    '#title' => t('Prefetch for anonymous users only'),
    '#description' => t('Highly recommended. Quicklink library will not be loaded for authenticated users.'),
    '#default_value' => variable_get('quicklink_no_load_when_authenticated', 1),
  );
  $form['when_load_library']['quicklink_no_load_when_session'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not prefetch during sessions'),
    '#description' => t('Recommended. Disables loading of the Quicklink library when a PHP session has been started. Useful for modules that use sessions (e.g. Drupal Commerce shopping carts).'),
    '#default_value' => variable_get('quicklink_no_load_when_session', 1),
  );
  $form['when_load_library']['quicklink_no_load_without_page_cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not prefetch if page caching for anonymous users is disabled'),
    '#description' => t('Highly recommended. Disables loading of the Quicklink library when page caching for anonymous users is disabled.'),
    '#default_value' => variable_get('quicklink_no_load_without_page_cache', 1),
  );
  $form['when_load_library']['quicklink_no_load_without_block_cache'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not prefetch if block caching is disabled'),
    '#description' => t('Highly recommended. Disables loading of the Quicklink library when block caching is disabled.'),
    '#default_value' => variable_get('quicklink_no_load_without_block_cache', 1),
  );
  $options = array();
  $types = node_type_get_types();
  foreach ($types as $type) {
    $options[$type->type] = $type->name;
  }
  $form['when_load_library']['quicklink_no_load_content_types'] = array(
    '#title' => t('Do not load library on these content types:'),
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => variable_get('quicklink_no_load_content_types', array()),
  );

  // Polyfill tab.
  $form['polyfill'] = array(
    '#type' => 'fieldset',
    '#title' => t('Extended Browser Support'),
    '#description' => t('On this tab, include support of additional browsers via polyfill.'),
    '#group' => 'settings',
  );
  $form['polyfill']['quicklink_load_polyfill'] = array(
    '#type' => 'checkbox',
    '#title' => t('Load <em>Intersection Observer</em> polyfill'),
    '#description' => t('This checkbox will enable loading of necessary polyfills from <a href="https://polyfill.io" target="_blank">polyfill.io</a>. This will enable usage of Quicklink in IE11 and older versions modern browsers.'),
    '#default_value' => variable_get('quicklink_load_polyfill', 1),
  );

  // Debug tab.
  $form['debug'] = array(
    '#type' => 'fieldset',
    '#title' => t('Debug'),
    '#description' => t('On this tab, enable debug logging.'),
    '#group' => 'settings',
  );
  $form['debug']['quicklink_enable_debug_mode'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable debug mode'),
    '#description' => t("Log Quicklink development information to the HTML and JavaScript console. You may need to clear Drupal's cache after changing this value."),
    '#default_value' => variable_get('quicklink_enable_debug_mode', 0),
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (variable_get('quicklink_enable_debug_mode', 0)) {
    drupal_set_message('Quicklink debug mode enabled. Be sure to disable this on production.', 'warning');
  }
  return $form;
}