Commit 3a18fe74 authored by Tim Rohaly's avatar Tim Rohaly Committed by Tim Rohaly
Browse files

Issue #2415835 by krisahil, TR: On core performance page, warn about...

Issue #2415835 by krisahil, TR: On core performance page, warn about honeypot's disabling of page cache
parent 5b4238b1
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_help().
@@ -40,6 +41,30 @@ function honeypot_cron() {
    ->execute();
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function honeypot_form_system_performance_settings_alter(&$form, FormStateInterface $form_state, $form_id) {
  // If time-based protection is effectively disabled, no need for a warning.
  if (\Drupal::config('honeypot.settings')->get('time_limit') === 0) {
    return;
  }

  // Add a warning about caching on the Performance settings page.
  $description = '';
  if (!empty($form['caching']['page_cache_maximum_age']['#description'])) {
    // If there's existing description on 'caching' field, append a break to it
    // so that our verbiage is on its own line.
    $description .= $form['caching']['page_cache_maximum_age']['#description'] . '<br />';
  }

  $description .= t('<em>Page caching may be disabled on any pages where a form is present due to the <a href=":url">Honeypot module\'s configuration</a>.</em>', [
    ':url' => Url::fromRoute('honeypot.config')->toString(),
  ]);

  $form['caching']['page_cache_maximum_age']['#description'] = $description;
}

/**
 * Implements hook_form_alter().
 *