Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / src / Form / PerformanceForm.php
index 2ec5043589050bc49580b2261dbb6648a9bacf5b..9d19b7599c35cd821dcea7a59267bb4292ccb6a3 100644 (file)
@@ -3,10 +3,12 @@
 namespace Drupal\system\Form;
 
 use Drupal\Core\Asset\AssetCollectionOptimizerInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Datetime\DateFormatterInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Url;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -37,6 +39,13 @@ class PerformanceForm extends ConfigFormBase {
    */
   protected $jsCollectionOptimizer;
 
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
   /**
    * Constructs a PerformanceForm object.
    *
@@ -48,13 +57,16 @@ class PerformanceForm extends ConfigFormBase {
    *   The CSS asset collection optimizer service.
    * @param \Drupal\Core\Asset\AssetCollectionOptimizerInterface $js_collection_optimizer
    *   The JavaScript asset collection optimizer service.
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
    */
-  public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter, AssetCollectionOptimizerInterface $css_collection_optimizer, AssetCollectionOptimizerInterface $js_collection_optimizer) {
+  public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter, AssetCollectionOptimizerInterface $css_collection_optimizer, AssetCollectionOptimizerInterface $js_collection_optimizer, ModuleHandlerInterface $module_handler) {
     parent::__construct($config_factory);
 
     $this->dateFormatter = $date_formatter;
     $this->cssCollectionOptimizer = $css_collection_optimizer;
     $this->jsCollectionOptimizer = $js_collection_optimizer;
+    $this->moduleHandler = $module_handler;
   }
 
   /**
@@ -65,7 +77,8 @@ class PerformanceForm extends ConfigFormBase {
       $container->get('config.factory'),
       $container->get('date.formatter'),
       $container->get('asset.css.collection_optimizer'),
-      $container->get('asset.js.collection_optimizer')
+      $container->get('asset.js.collection_optimizer'),
+      $container->get('module_handler')
     );
   }
 
@@ -107,7 +120,6 @@ class PerformanceForm extends ConfigFormBase {
       '#type' => 'details',
       '#title' => t('Caching'),
       '#open' => TRUE,
-      '#description' => $this->t('Note: Drupal provides an internal page cache module that is recommended for small to medium-sized websites.'),
     ];
     // Identical options to the ones for block caching.
     // @see \Drupal\Core\Block\BlockBase::buildConfigurationForm()
@@ -116,10 +128,14 @@ class PerformanceForm extends ConfigFormBase {
     $period[0] = '<' . t('no caching') . '>';
     $form['caching']['page_cache_maximum_age'] = [
       '#type' => 'select',
-      '#title' => t('Page cache maximum age'),
+      '#title' => t('Browser and proxy cache maximum age'),
       '#default_value' => $config->get('cache.page.max_age'),
       '#options' => $period,
-      '#description' => t('The maximum time a page can be cached by browsers and proxies. This is used as the value for max-age in Cache-Control headers.'),
+      '#description' => t('This is used as the value for max-age in Cache-Control headers.'),
+    ];
+    $form['caching']['internal_page_cache'] = [
+      '#markup' => $this->t('Drupal provides an <a href=":module_enable">Internal Page Cache module</a> that is recommended for small to medium-sized websites.', [':module_enable' => Url::fromRoute('system.modules_list')->toString()]),
+      '#access' => !$this->moduleHandler->moduleExists('page_cache'),
     ];
 
     $directory = 'public://';
@@ -174,7 +190,7 @@ class PerformanceForm extends ConfigFormBase {
    */
   public function submitCacheClear(array &$form, FormStateInterface $form_state) {
     drupal_flush_all_caches();
-    drupal_set_message(t('Caches cleared.'));
+    $this->messenger()->addStatus($this->t('Caches cleared.'));
   }
 
 }