Form builder; Configure advagg settings.

See also

system_settings_form()

Related topics

1 string reference to 'advagg_admin_settings_form'
advagg_menu in ./advagg.module
Implements hook_menu().

File

./advagg.admin.inc, line 19

Code

function advagg_admin_settings_form($form, $form_state) {
    drupal_set_title(t('AdvAgg: Configuration'));
    advagg_display_message_if_requirements_not_met();
    $config_path = advagg_admin_config_root_path();
    $options = array(
        0 => t('Use default (safe) settings'),
        2 => t('Use recommended (optimized) settings'),
        4 => t('Use customized settings'),
    );
    $form['advagg_admin_mode'] = array(
        '#type' => 'radios',
        '#title' => t('AdvAgg Settings'),
        '#default_value' => variable_get('advagg_admin_mode', ADVAGG_ADMIN_MODE),
        '#options' => $options,
        '#description' => t("Default settings will mirror core as closely as possible. <br>Recommended settings are optimized for speed."),
    );
    $form['global_container'] = array(
        '#type' => 'container',
        '#hidden' => TRUE,
        '#states' => array(
            'visible' => array(
                ':input[name="advagg_admin_mode"]' => array(
                    'value' => '4',
                ),
            ),
        ),
    );
    // Simple checkbox settings.
    $form['global_container']['global'] = array(
        '#type' => 'fieldset',
        '#title' => t('Global Options'),
    );
    $form['global_container']['global']['advagg_enabled'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable advanced aggregation (recommended)'),
        '#default_value' => variable_get('advagg_enabled', ADVAGG_ENABLED),
        '#description' => t('Uncheck this box to completely disable AdvAgg functionality.'),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['global']['advagg_remote_version_check'] = array(
        '#type' => 'checkbox',
        '#title' => t('Check remote/github libraries for the latest version'),
        '#default_value' => variable_get('advagg_remote_version_check', ADVAGG_REMOTE_VERSION_CHECK),
        '#description' => t('This will check for the latest versions of various libraries used by AdvAgg on select admin pages. In some environments you may wish to not do these checks; uncheck this box to disable remote checks.'),
    );
    $advagg_core_groups_default = variable_get('advagg_core_groups', ADVAGG_CORE_GROUPS);
    if (variable_get('advagg_combine_css_media', ADVAGG_COMBINE_CSS_MEDIA) || variable_get('advagg_ie_css_selector_limiter', ADVAGG_IE_CSS_SELECTOR_LIMITER) || module_exists('advagg_bundler') && variable_get('advagg_bundler_active', ADVAGG_BUNDLER_ACTIVE)) {
        $advagg_core_groups_default = FALSE;
    }
    $form['global_container']['global']['advagg_core_groups'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use cores grouping logic'),
        '#default_value' => $advagg_core_groups_default,
        '#description' => t('Will group files just like core does.'),
        '#recommended_value' => FALSE,
        '#states' => array(
            'enabled' => array(
                '#edit-advagg-combine-css-media' => array(
                    'checked' => FALSE,
                ),
                '#edit-advagg-ie-css-selector-limiter' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    $form['global_container']['global']['advagg_use_httprl'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use HTTPRL to generate aggregates (recommended)'),
        '#default_value' => module_exists('httprl') ? variable_get('advagg_use_httprl', ADVAGG_USE_HTTPRL) : FALSE,
        '#disabled' => module_exists('httprl') ? FALSE : TRUE,
        '#description' => t('If <a href="@link">HTTPRL</a> is installed, advagg will use it to generate aggregates on the fly in a background parallel process.', array(
            '@link' => 'http://drupal.org/project/httprl',
        )),
        '#recommended_value' => TRUE,
    );
    $aggressive_cache_conflicts = advagg_aggressive_cache_conflicts();
    if (empty($aggressive_cache_conflicts)) {
        $description = t('It appears that there are no incompatible modules, so you should be able to safely use the Aggressive cache.');
    }
    else {
        $description = t('It appears that there might be some incompatible modules. I would test these out before setting the cache to aggressive: %modules', array(
            '%modules' => implode(', ', $aggressive_cache_conflicts),
        ));
    }
    $options = array(
        -1 => t('Development ~ 300ms'),
        1 => t('Normal ~ 60ms'),
        3 => t('Render Cache ~ 30ms (recommended)'),
        5 => t('Aggressive Render Cache ~ 10ms'),
    );
    $form['global_container']['global']['advagg_cache_level'] = array(
        '#type' => 'radios',
        '#title' => t('AdvAgg Cache Settings'),
        '#default_value' => variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL),
        '#options' => $options,
        '#recommended_value' => 3,
        '#description' => t("As a reference, core takes about 25 ms to run. Development will scan all files for a change on every page load. Normal and the render cache is fine for all use cases. Aggressive should be fine for most use cases. If your inline css/js changes based off of a variable then the cache hit ratio will be low; if that is the case consider using Drupal.settings for a better cache hit ratio when using the render cache. The aggressive render cache will cache the output from js_alter and css_alter. !description", array(
            '@information' => url($config_path . '/advagg/info', array(
                'fragment' => 'edit-hooks-implemented',
            )),
            '!description' => $description,
        )),
    );
    $stream_wrappers = file_get_stream_wrappers();
    $prefix = variable_get('advagg_root_dir_prefix', ADVAGG_ROOT_DIR_PREFIX);
    if ($prefix !== 'public://' || $stream_wrappers['public']['class'] !== 'DrupalPublicStreamWrapper' || count($stream_wrappers) > 2 || file_default_scheme() !== 'public') {
        $stream_wrappers_string = array();
        foreach ($stream_wrappers as $key => $values) {
            $stream_wrappers_string[] = t("<strong>@key://</strong> uses @class; @description", array(
                '@key' => $key,
                '@class' => $values['class'],
                '@description' => $values['description'],
            ));
        }
        $stream_wrappers_string = implode("<br>\n", $stream_wrappers_string);
        $form['global_container']['global']['advagg_root_dir_prefix'] = array(
            '#type' => 'textfield',
            '#title' => t('Stream wrapper for AdvAgg.'),
            '#default_value' => $prefix,
            '#description' => t("Options:<br>\n!stream_wrappers", array(
                '!stream_wrappers' => $stream_wrappers_string,
            )),
        );
    }
    $form['global_container']['global']['dev_container'] = array(
        '#type' => 'container',
        '#states' => array(
            'visible' => array(
                ':input[name="advagg_cache_level"]' => array(
                    'value' => '-1',
                ),
            ),
        ),
    );
    // Show msg about advagg css compress.
    if (module_exists('advagg_css_compress') && (variable_get('advagg_css_compressor', ADVAGG_CSS_COMPRESSOR) > 0 || variable_get('advagg_css_compress_inline', ADVAGG_CSS_COMPRESS_INLINE))) {
        $form['global_container']['global']['dev_container']['advagg_css_compress_msg'] = array(
            '#markup' => '<p>' . t('The <a href="@css">AdvAgg CSS Compression module</a> is disabled when in development mode.', array(
                '@css' => url($config_path . '/advagg/css-compress'),
            )) . '</p>',
        );
    }
    // Show msg about advagg js compress.
    if (module_exists('advagg_js_compress') && (variable_get('advagg_js_compressor', ADVAGG_JS_COMPRESSOR) || variable_get('advagg_js_compress_inline', ADVAGG_JS_COMPRESS_INLINE))) {
        $form['global_container']['global']['dev_container']['advagg_js_compress_msg'] = array(
            '#markup' => '<p>' . t('The <a href="@js">AdvAgg JS Compression module</a> is disabled when in development mode.', array(
                '@js' => url($config_path . '/advagg/js-compress'),
            )) . '</p>',
        );
    }
    // Show msg about the jquery update compression setting.
    if (module_exists('jquery_update')) {
        if (variable_get('jquery_update_compression_type', 'min') === 'min') {
            $form['global_container']['global']['dev_container']['advagg_jquery_update_development'] = array(
                '#markup' => '<p>' . t('You might want to change the <a href="!url">jQuery update compression level</a> to "Development" as well.', array(
                    '!url' => url('admin/config/development/jquery_update'),
                )) . '</p>',
            );
        }
        else {
            $form['global_container']['global']['prod_container'] = array(
                '#type' => 'container',
                '#states' => array(
                    'visible' => array(
                        ':input[name="advagg_cache_level"]' => array(
                            '!value' => '-1',
                        ),
                    ),
                ),
            );
            $form['global_container']['global']['prod_container']['advagg_jquery_update_development'] = array(
                '#markup' => '<p>' . t('You might want to change the <a href="!url">jQuery update compression level</a> to "Production" as well.', array(
                    '!url' => url('admin/config/development/jquery_update'),
                )) . '</p>',
            );
        }
    }
    $advagg_resource_hints_dns_prefetch = variable_get('advagg_resource_hints_dns_prefetch', ADVAGG_RESOURCE_HINTS_DNS_PREFETCH);
    $advagg_resource_hints_preconnect = variable_get('advagg_resource_hints_preconnect', ADVAGG_RESOURCE_HINTS_PRECONNECT);
    $advagg_resource_hints_preload = variable_get('advagg_resource_hints_preload', ADVAGG_RESOURCE_HINTS_PRELOAD);
    $form['global_container']['global']['resource_hints'] = array(
        '#type' => 'fieldset',
        '#title' => t('Resource Hints'),
        '#collapsible' => TRUE,
        '#collapsed' => $advagg_resource_hints_dns_prefetch || $advagg_resource_hints_preconnect || $advagg_resource_hints_preload ? FALSE : TRUE,
        '#description' => t('Preemptively get resources (CSS/JS & sub requests).'),
    );
    $form['global_container']['global']['resource_hints']['advagg_resource_hints_dns_prefetch'] = array(
        '#type' => 'checkbox',
        '#title' => t('DNS Prefetch (recommended).'),
        '#default_value' => $advagg_resource_hints_dns_prefetch,
        '#disabled' => '',
        '#description' => t('Start the DNS lookup for external CSS and JavaScript files as soon as possible.'),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['global']['resource_hints']['advagg_resource_hints_preconnect'] = array(
        '#type' => 'checkbox',
        '#title' => t('Preconnect (recommended).'),
        '#default_value' => $advagg_resource_hints_preconnect,
        '#disabled' => '',
        '#description' => t('Start the connection to external resources before an HTTP request is actually sent to the server.'),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['global']['resource_hints']['advagg_resource_hints_location'] = array(
        '#type' => 'radios',
        '#title' => t('Location of resource hints.'),
        '#default_value' => variable_get('advagg_resource_hints_location', ADVAGG_RESOURCE_HINTS_LOCATION),
        '#description' => t('If you have css and/or js files being loaded right after the "charset=utf-8" meta tag, you need to use the "above charset=utf-8" option in order for some of the resource hints to work; Optimizely is an example that would need this other option. Link headers are not supported in every browser.'),
        '#recommended_value' => 1,
        '#options' => array(
            1 => t('Below charset=utf-8 (recommended)'),
            3 => t('Above charset=utf-8'),
        ),
        '#states' => array(
            'disabled' => array(
                '#edit-advagg-resource-hints-dns-prefetch' => array(
                    'checked' => FALSE,
                ),
                '#edit-advagg-resource-hints-preconnect' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    // Preload Section.
    $form['global_container']['global']['resource_hints']['preload']['advagg_resource_hints_preload'] = array(
        '#type' => 'checkbox',
        '#title' => t('Preload link http headers.'),
        '#default_value' => $advagg_resource_hints_preload,
        '#disabled' => '',
        '#description' => t('Use link http headers to send out preload hints for local and external resources.'),
        '#recommended_value' => FALSE,
    );
    $advagg_resource_hints_preload_settings = advagg_get_resource_hints_preload_settings();
    $form['global_container']['global']['resource_hints']['preload']['advagg_resource_hints_preload_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Preload Ordering and Settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Change the order of what preload items get sent first. Can also control what will be sent and if HTTP/2 push should be used (if your server supports it). If your webserver supports HTTP/2 Push, and it is enabled, the server will send every asset flagged to be pushed to the browser on every request, ignoring the browser cache (not a good thing for repeat visits). More complex server configuration will be needed to make this efficient; no solutions are currently available.'),
        '#states' => array(
            'invisible' => array(
                '#edit-advagg-resource-hints-preload' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    // Build the rows.
    foreach ($advagg_resource_hints_preload_settings as $id => $entry) {
        // Build the table rows.
        $rows[$id] = array(
            'data' => array(
                // Cell for the cross drag and drop element.
array(
                    'class' => array(
                        'entry-cross',
                    ),
                ),
                // Weight item for the tabledrag.
array(
                    'data' => array(
                        '#type' => 'weight',
                        '#title' => t('Weight'),
                        '#title_display' => 'invisible',
                        '#default_value' => $entry['#weight'],
                        '#parents' => array(
                            'advagg_resource_hints_preload_settings',
                            $id,
                            'weight',
                        ),
                        '#attributes' => array(
                            'class' => array(
                                'entry-order-weight',
                            ),
                        ),
                    ),
                ),
                check_plain($entry['title']),
                array(
                    'data' => array(
                        '#type' => 'checkbox',
                        '#title' => t('Enable'),
                        '#title_display' => 'invisible',
                        '#default_value' => $entry['enabled'],
                        '#parents' => array(
                            'advagg_resource_hints_preload_settings',
                            $id,
                            'enabled',
                        ),
                    ),
                ),
                array(
                    'data' => array(
                        '#type' => 'checkbox',
                        '#title' => t('HTTP/2 Push'),
                        '#title_display' => 'invisible',
                        '#default_value' => $entry['push'],
                        '#parents' => array(
                            'advagg_resource_hints_preload_settings',
                            $id,
                            'push',
                        ),
                    ),
                ),
                array(
                    'data' => array(
                        '#type' => 'checkbox',
                        '#title' => t('Local'),
                        '#title_display' => 'invisible',
                        '#default_value' => $entry['local'],
                        '#parents' => array(
                            'advagg_resource_hints_preload_settings',
                            $id,
                            'local',
                        ),
                    ),
                ),
                array(
                    'data' => array(
                        '#type' => 'checkbox',
                        '#title' => t('External'),
                        '#title_display' => 'invisible',
                        '#default_value' => $entry['external'],
                        '#parents' => array(
                            'advagg_resource_hints_preload_settings',
                            $id,
                            'external',
                        ),
                    ),
                ),
            ),
            'class' => array(
                'draggable',
            ),
        );
        // Build rows of the form elements in the table.
        $row_elements[$id] = array(
            'weight' => &$rows[$id]['data'][1]['data'],
            'enabled' => &$rows[$id]['data'][3]['data'],
            'push' => &$rows[$id]['data'][4]['data'],
            'local' => &$rows[$id]['data'][5]['data'],
            'external' => &$rows[$id]['data'][6]['data'],
        );
    }
    // Add the table to the form.
    $form['global_container']['global']['resource_hints']['preload']['advagg_resource_hints_preload_settings']['advagg_table'] = array(
        '#theme' => 'table',
        // The row form elements need to be processed and build,
        // therefore pass them as element children.
'elements' => $row_elements,
        '#header' => array(
            // We need two empty columns for the weight field and the cross.
array(
                'data' => NULL,
                'colspan' => 2,
            ),
            t('Name'),
            t('Enabled'),
            t('HTTP/2 Push'),
            t('Local'),
            t('External'),
        ),
        '#rows' => $rows,
        '#attributes' => array(
            'id' => 'entry-order',
        ),
    );
    drupal_add_tabledrag('entry-order', 'order', 'sibling', 'entry-order-weight');
    $form['global_container']['global']['resource_hints']['preload']['advagg_resource_hints_preload_settings']['advagg_resource_hints_preload_reset'] = array(
        '#type' => 'submit',
        '#value' => t('Reset'),
        '#submit' => array(
            'advagg_admin_resource_hints_preload_reset',
        ),
    );
    $form['global_container']['global']['resource_hints']['advagg_resource_hints_use_immutable'] = array(
        '#type' => 'checkbox',
        '#title' => t('Send immutable header for all aggregated files (recommended).'),
        '#default_value' => variable_get('advagg_resource_hints_use_immutable', ADVAGG_RESOURCE_HINTS_USE_IMMUTABLE),
        '#description' => t('Have Apache send <a href="@url1">Cache-Control: immutable</a> for all aggregated files. Current <a href="@url2">browser support</a>', array(
            '@url1' => 'http://bitsup.blogspot.de/2016/05/cache-control-immutable.html',
            '@url2' => 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Browser_compatibility',
        )),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['global']['cron'] = array(
        '#type' => 'fieldset',
        '#title' => t('Cron Options'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Unless you have a good reason to adjust these values you should leave them alone.'),
    );
    // @codingStandardsIgnoreStart
    $short_times = drupal_map_assoc(array(
        60 * 15,
        // 15 min.
60 * 30,
        // 30 min.
60 * 45,
        // 45 min.
60 * 60,
        // 1 hour.
60 * 60 * 2,
        // 2 hours.
60 * 60 * 4,
        // 4 hours.
60 * 60 * 6,
        // 6 hours.
60 * 60 * 8,
        // 8 hours.
60 * 60 * 10,
        // 10 hours.
60 * 60 * 12,
        // 12 hours.
60 * 60 * 18,
        // 18 hours.
60 * 60 * 23,
        // 23 hours.
60 * 60 * 24,
        // 1 day.
60 * 60 * 24 * 2,
    ), 'format_interval');
    $long_times = drupal_map_assoc(array(
        60 * 60 * 24 * 2,
        // 2 days.
60 * 60 * 24 * 3,
        // 3 days.
60 * 60 * 24 * 4,
        // 4 days.
60 * 60 * 24 * 5,
        // 5 days.
60 * 60 * 24 * 6,
        // 6 days.
60 * 60 * 24 * 7,
        // 1 week.
60 * 60 * 24 * 7 * 2,
        // 2 weeks.
60 * 60 * 24 * 7 * 3,
        // 3 weeks.
60 * 60 * 24 * 30,
        // 1 month.
60 * 60 * 24 * 45,
        // 1 month 2 weeks.
60 * 60 * 24 * 60,
    ), 'format_interval');
    // @codingStandardsIgnoreEnd
    $last_ran = variable_get('advagg_cron_timestamp', 0);
    if (!empty($last_ran)) {
        $last_ran = t('@time ago', array(
            '@time' => format_interval(REQUEST_TIME - $last_ran),
        ));
    }
    else {
        $last_ran = t('never');
    }
    $form['global_container']['global']['cron']['advagg_cron_frequency'] = array(
        '#type' => 'select',
        '#options' => $short_times,
        '#title' => 'Minimum amount of time between advagg_cron() runs.',
        '#default_value' => variable_get('advagg_cron_frequency', ADVAGG_CRON_FREQUENCY),
        '#description' => t('The default value for this is %value. The last time advagg_cron was ran is %time.', array(
            '%value' => format_interval(ADVAGG_CRON_FREQUENCY),
            '%time' => $last_ran,
        )),
    );
    $form['global_container']['global']['cron']['drupal_stale_file_threshold'] = array(
        '#type' => 'select',
        '#options' => $long_times,
        '#title' => 'Delete aggregates accessed/modified more than a set time ago.',
        // @codingStandardsIgnoreLine
'#default_value' => variable_get('drupal_stale_file_threshold', 2592000),
        '#description' => t('The default value for this is %value.', array(
            '%value' => format_interval(2592000),
        )),
    );
    $form['global_container']['global']['cron']['advagg_remove_missing_files_from_db_time'] = array(
        '#type' => 'select',
        '#options' => $long_times,
        '#title' => 'How long to wait until unaccessed aggregates with missing files are removed from the database.',
        '#default_value' => variable_get('advagg_remove_missing_files_from_db_time', ADVAGG_REMOVE_MISSING_FILES_FROM_DB_TIME),
        '#description' => t('The default value for this is %value.', array(
            '%value' => format_interval(ADVAGG_REMOVE_MISSING_FILES_FROM_DB_TIME),
        )),
    );
    $form['global_container']['global']['cron']['advagg_remove_old_unused_aggregates_time'] = array(
        '#type' => 'select',
        '#options' => $long_times,
        '#title' => 'How long to wait until unaccessed aggregates are removed from the database.',
        '#default_value' => variable_get('advagg_remove_old_unused_aggregates_time', ADVAGG_REMOVE_OLD_UNUSED_AGGREGATES_TIME),
        '#description' => t('The default value for this is %value.', array(
            '%value' => format_interval(ADVAGG_REMOVE_OLD_UNUSED_AGGREGATES_TIME),
        )),
    );
    $form['global_container']['global']['obscure'] = array(
        '#type' => 'fieldset',
        '#title' => t('Obscure Options'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Some of the more obscure AdvAgg settings. Odds are you do not need to change anything in here.'),
    );
    $form['global_container']['global']['obscure']['advagg_gzip'] = array(
        '#type' => 'checkbox',
        '#title' => t('Create .gz files'),
        '#default_value' => variable_get('advagg_gzip', ADVAGG_GZIP),
        '#description' => t('All aggregated files can be pre-compressed into a .gz file and
   served from Apache. This is faster then gzipping the file on each request.'),
    );
    $form['global_container']['global']['obscure']['advagg_brotli'] = array(
        '#type' => 'checkbox',
        '#title' => t('Create .br files'),
        '#default_value' => variable_get('advagg_brotli', ADVAGG_BROTLI),
        '#description' => t('All aggregated files can be pre-compressed into a .br file and
  served from Apache. This is faster then brotli compressing the file on each request.'),
    );
    if (!function_exists('brotli_compress') || !defined('BROTLI_TEXT')) {
        $form['global_container']['global']['obscure']['advagg_brotli']['#default_value'] = FALSE;
        $form['global_container']['global']['obscure']['advagg_brotli']['#disabled'] = TRUE;
        $form['global_container']['global']['obscure']['advagg_brotli']['#description'] .= ' ' . t('The <a href="@url">PHP brotli extension</a> is needed in order to enable this feature.', array(
            '@url' => 'https://github.com/kjdev/php-ext-brotli',
        ));
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            $form['global_container']['global']['obscure']['advagg_brotli']['#description'] .= ' ' . t('If running on windows this is a helpful guide on how to compile <a href="@url">PHP extensions</a>. Also noted that <a href="@iis">IIS has a Brotli extension</a>,', array(
                '@url' => 'https://wiki.php.net/internals/windows/stepbystepbuild',
                '@iis' => 'https://www.iis.net/downloads/community/2016/03/iis-brotli',
            ));
        }
    }
    $form['global_container']['global']['obscure']['advagg_ajax_render_alter'] = array(
        '#type' => 'checkbox',
        '#title' => t('Run advagg_ajax_render_alter()'),
        '#default_value' => variable_get('advagg_ajax_render_alter', ADVAGG_AJAX_RENDER_ALTER),
        '#description' => t('If disabled, AdvAgg will not alter the aggregates returned by ajax requests.'),
    );
    $form['global_container']['global']['obscure']['advagg_include_base_url'] = array(
        '#type' => 'checkbox',
        '#title' => t('Include the base_url variable in the hooks hash array.'),
        '#default_value' => variable_get('advagg_include_base_url', ADVAGG_INCLUDE_BASE_URL),
        '#description' => t('If you would like a unique set of aggregates for every permutation of the base_url (current value: %value) then enable this setting. <a href="@issue">Read more</a>.', array(
            '%value' => $GLOBALS['base_url'],
            '@issue' => 'https://www.drupal.org/node/2353811',
        )),
    );
    $form['global_container']['global']['obscure']['advagg_convert_absolute_to_relative_path'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert absolute paths to be self references.'),
        '#default_value' => variable_get('advagg_convert_absolute_to_relative_path', ADVAGG_CONVERT_ABSOLUTE_TO_RELATIVE_PATH),
        '#description' => t('If the src to a CSS/JS file points to this domain, convert the absolute path to a relative path. Will also convert url() references inside of css files. This is generally safe unless the drupal page will be embedded, like it is when used as an iframe.'),
    );
    $form['global_container']['global']['obscure']['advagg_convert_absolute_to_protocol_relative_path'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert absolute paths to be protocol relative paths.'),
        '#default_value' => variable_get('advagg_convert_absolute_to_protocol_relative_path', ADVAGG_CONVERT_ABSOLUTE_TO_PROTOCOL_RELATIVE_PATH),
        '#description' => t('If the src to a CSS/JS file points starts with http:// or https://, convert it to use a protocol relative path //. Will also convert url() references inside of css files. This is incompatible with IE6 and might cause extra bandwidth usage in IE7 and IE8 in regards to url() statements inside css files. According to <a href="@url">current web browser market share</a> IE 6 is less than 0.2% of the total number of browsers in use and IE 7+8 make up under 5% of browsers in use.', array(
            '@url' => 'http://www.w3counter.com/trends',
        )),
        '#states' => array(
            'enabled' => array(
                '#edit-advagg-force-https-path' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    $form['global_container']['global']['obscure']['advagg_force_https_path'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert http:// to https://.'),
        '#default_value' => variable_get('advagg_force_https_path', ADVAGG_FORCE_HTTPS_PATH),
        '#description' => t('If the src to a CSS/JS file starts with http:// convert it https://. Will also convert url() references inside of css files.'),
        '#states' => array(
            'enabled' => array(
                '#edit-advagg-convert-absolute-to-protocol-relative-path' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    $form['global_container']['global']['obscure']['advagg_css_absolute_path'] = array(
        '#type' => 'checkbox',
        '#title' => t('Convert CSS url() to absolute paths if file is outside of the public:// dir.'),
        '#default_value' => variable_get('advagg_css_absolute_path', ADVAGG_CSS_ABSOLUTE_PATH),
        '#description' => t('Useful for CSS files hosted on S3 where the referenced files inside of url() is not in the same location as the aggregated CSS file.'),
    );
    $form['global_container']['global']['obscure']['advagg_skip_file_create_url_inside_css'] = array(
        '#type' => 'checkbox',
        '#title' => t('Do not run CSS url() values through file_create_url().'),
        '#default_value' => variable_get('advagg_skip_file_create_url_inside_css', ADVAGG_SKIP_FILE_CREATE_URL_INSIDE_CSS),
        '#description' => t('If checked, the processing of url() values within CSS will be handled more like core than the CDN module. This will not convert relative paths in your source CSS to absolute paths in the aggregated CSS.'),
    );
    $form['global_container']['global']['obscure']['advagg_htaccess_symlinksifownermatch'] = array(
        '#type' => 'checkbox',
        '#title' => t('Use "Options +SymLinksIfOwnerMatch"'),
        '#default_value' => variable_get('advagg_htaccess_symlinksifownermatch', ADVAGG_HTACCESS_SYMLINKSIFOWNERMATCH),
        '#description' => t('By default the custom .htaccess files are configured to use "<code>Options +FollowSymLinks</code>". Some hosting companies do not support this so "<code>Options +SymLinksIfOwnerMatch</code>" must be used instead.'),
    );
    $form['global_container']['global']['obscure']['advagg_disable_on_admin'] = array(
        '#type' => 'checkbox',
        '#title' => t('Do not use AdvAgg or any aggregation in the admin section.'),
        '#default_value' => variable_get('advagg_disable_on_admin', ADVAGG_DISABLE_ON_ADMIN),
        '#description' => t('If checked, AdvAgg will not be used in the /admin section as well as any place the admin theme is used.'),
    );
    $form['global_container']['global']['obscure']['advagg_disable_on_listed_pages'] = array(
        '#type' => 'textarea',
        '#title' => t('Do not use AdvAgg or any aggregation in the following pages'),
        '#default_value' => variable_get('advagg_disable_on_listed_pages', ADVAGG_DISABLE_ON_LISTED_PAGES),
        '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog.", array(
            '%blog' => 'blog',
            '%blog-wildcard' => 'blog/*',
        )),
    );
    // Get core htaccess files.
    $core_htaccess = advagg_htaccess_rewritebase();
    $advagg_htaccess_rewritebase = variable_get('advagg_htaccess_rewritebase', ADVAGG_HTACCESS_REWRITEBASE);
    if (!empty($core_htaccess)) {
        // Get advagg htaccess files.
        list($css_path, $js_path) = advagg_get_root_files_dir();
        $advagg_css_htaccess = advagg_htaccess_rewritebase($css_path[1]);
        $advagg_js_htaccess = advagg_htaccess_rewritebase($js_path[1]);
        // Build best guess dir name.
        $core_htaccess_directive = trim(str_ireplace('RewriteBase ', '', $core_htaccess));
        $new_dir = str_replace('//', '/', $core_htaccess_directive . '/' . dirname($css_path[1]));
        $form['global_container']['global']['obscure']['advagg_htaccess_rewritebase'] = array(
            '#type' => 'textfield',
            '#title' => t('AdvAgg RewriteBase Directive in .htaccess files.'),
            '#default_value' => $advagg_htaccess_rewritebase,
            '#description' => t('If gzip and/or brotli files are getting a 307 instead of a 200, this might fix the issue. This Drupal install is using "<code>@core_htaccess</code>" in the webroot .htaccess file. Based off of this and the current location of the advagg css/js directories (@css_path, @js_path) this is the recommended value for this field: <p><code>@best_guess</code><br></p> Current advagg htaccess values:<p><code>@advagg_css_htaccess</code><br><code>@advagg_js_htaccess</code></p> Note that the advagg CSS/JS directories are automatically added onto the end of the given input value.', array(
                '@core_htaccess' => $core_htaccess,
                '@best_guess' => $new_dir,
                '@css_path' => $css_path[1],
                '@js_path' => $js_path[1],
                '@advagg_css_htaccess' => $advagg_css_htaccess,
                '@advagg_js_htaccess' => $advagg_js_htaccess,
            )),
        );
    }
    elseif (!empty($advagg_htaccess_rewritebase)) {
        list($css_path, $js_path) = advagg_get_root_files_dir();
        $advagg_css_htaccess = advagg_htaccess_rewritebase($css_path[1]);
        $advagg_js_htaccess = advagg_htaccess_rewritebase($js_path[1]);
        // Offer advice if this setting should be disabled.
        $form['global_container']['global']['obscure']['advagg_htaccess_rewritebase'] = array(
            '#type' => 'textfield',
            '#title' => t('AdvAgg RewriteBase Directive in .htaccess files.'),
            '#default_value' => $advagg_htaccess_rewritebase,
            '#description' => t('This Drupal install is no longer using RewriteBase in the webroot .htaccess file. The recommended value for this field is a blank string (empty) <br>Current advagg htaccess values:<p><code>@advagg_css_htaccess</code><br><code>@advagg_js_htaccess</code></p>', array(
                '@advagg_css_htaccess' => $advagg_css_htaccess,
                '@advagg_js_htaccess' => $advagg_js_htaccess,
            )),
        );
    }
    $form['global_container']['css'] = array(
        '#type' => 'fieldset',
        '#title' => t('CSS Options'),
    );
    $form['global_container']['css']['advagg_combine_css_media'] = array(
        '#type' => 'checkbox',
        '#title' => t('Combine CSS files by using media queries (recommended)'),
        '#default_value' => variable_get('advagg_combine_css_media', ADVAGG_COMBINE_CSS_MEDIA),
        '#description' => t('Will combine more CSS files together because different CSS media types can be used in the same file by using media queries. Use cores grouping logic needs to be unchecked in order for this to work. Also noted is that due to an issue with IE9, compatibility mode is forced off if this is enabled.'),
        '#states' => array(
            'disabled' => array(
                '#edit-advagg-core-groups' => array(
                    'checked' => TRUE,
                ),
            ),
        ),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['css']['advagg_ie_css_selector_limiter'] = array(
        '#type' => 'checkbox',
        '#title' => t('Prevent more than %limit CSS selectors in an aggregated CSS file', array(
            '%limit' => variable_get('advagg_ie_css_selector_limiter_value', ADVAGG_IE_CSS_SELECTOR_LIMITER_VALUE),
        )),
        '#default_value' => variable_get('advagg_ie_css_selector_limiter', ADVAGG_IE_CSS_SELECTOR_LIMITER),
        '#description' => t('Internet Explorer before version 10; IE9, IE8, IE7, and IE6 all have 4095 as the limit for the maximum number of css selectors that can be in a file. Enabling this will prevent CSS aggregates from being created that exceed this limit. <a href="@link">More info</a>. Use cores grouping logic needs to be unchecked in order for this to work.', array(
            '@link' => 'http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/10164546.aspx',
        )),
        '#states' => array(
            'disabled' => array(
                '#edit-advagg-core-groups' => array(
                    'checked' => TRUE,
                ),
            ),
        ),
        '#recommended_value' => FALSE,
    );
    $form['global_container']['css']['advagg_ie_css_selector_limiter_value'] = array(
        '#type' => 'textfield',
        '#title' => t('The selector count the IE CSS limiter should use'),
        '#default_value' => variable_get('advagg_ie_css_selector_limiter_value', ADVAGG_IE_CSS_SELECTOR_LIMITER_VALUE),
        '#description' => t('Internet Explorer before version 10; IE9, IE8, IE7, and IE6 all have 4095 as the limit for the maximum number of css selectors that can be in a file. Use this field to modify the value used; 4095 sometimes may be still be too many with media queries.'),
        '#states' => array(
            'visible' => array(
                '#edit-advagg-ie-css-selector-limiter' => array(
                    'checked' => TRUE,
                ),
            ),
            'disabled' => array(
                '#edit-advagg-ie-css-selector-limiter' => array(
                    'checked' => FALSE,
                ),
            ),
        ),
    );
    $form['global_container']['css']['advagg_css_fix_type'] = array(
        '#type' => 'checkbox',
        '#title' => t('Fix improperly set type (recommended)'),
        '#default_value' => variable_get('advagg_css_fix_type', ADVAGG_CSS_FIX_TYPE),
        '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external. Note that if this is causing issues, odds are you have a double slash when there should be a single; see <a href="@link">this issue</a>', array(
            '@link' => 'https://www.drupal.org/node/2336217',
        )),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['css']['advagg_css_remove_empty_files'] = array(
        '#type' => 'checkbox',
        '#title' => t('Remove empty CSS files from aggregates (recommended)'),
        '#default_value' => variable_get('advagg_css_remove_empty_files', ADVAGG_CSS_REMOVE_EMPTY_FILES),
        '#description' => t('If an empty CSS file ends up being in its own aggregate, that aggregate can end up as a 404.'),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['js'] = array(
        '#type' => 'fieldset',
        '#title' => t('JS Options'),
    );
    $form['global_container']['js']['advagg_js_fix_type'] = array(
        '#type' => 'checkbox',
        '#title' => t('Fix improperly set type (recommended)'),
        '#default_value' => variable_get('advagg_js_fix_type', ADVAGG_JS_FIX_TYPE),
        '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external. Note that if this is causing issues, odds are you have a double slash when there should be a single; see <a href="@link">this issue</a>', array(
            '@link' => 'https://www.drupal.org/node/2336217',
        )),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['js']['advagg_js_remove_empty_files'] = array(
        '#type' => 'checkbox',
        '#title' => t('Remove empty JS files from aggregates (recommended)'),
        '#default_value' => variable_get('advagg_js_remove_empty_files', ADVAGG_JS_REMOVE_EMPTY_FILES),
        '#description' => t('If an empty JS file ends up being in its own aggregate, that aggregate can end up as a 404.'),
        '#recommended_value' => TRUE,
    );
    $form['global_container']['js']['advagg_scripts_scope_anywhere'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow for JS to be added to blocks and views'),
        '#default_value' => variable_get('advagg_scripts_scope_anywhere', ADVAGG_SCRIPTS_SCOPE_ANYWHERE),
        '#description' => t('The scope key when using drupal_add_js and friends can be used to insert script tags throughout the html body. To see possible insertion points set <code>@theme_debug</code> in your settings.php file and view the page source while looking for @comment html comments. Some example scopes: <p><code>!example</code></p>', array(
            '@theme_debug' => '$conf[\'theme_debug\'] = TRUE;',
            '@comment' => '<!-- AdvAgg * tag -->',
            '!example' => "page_top:prefix<br />block:prefix:system:powered-by<br />view:suffix:frontpage:page",
        )),
    );
    // Clear the cache bins on submit.
    $form['#submit'][] = 'advagg_admin_settings_form_submit';
    return system_settings_form($form);
}