Commit 73c3cea7 authored by catch's avatar catch
Browse files

Issue #3258433 by daniel_j, smustgrave, tedfordgif, quietone: Clear Caches...

Issue #3258433 by daniel_j, smustgrave, tedfordgif, quietone: Clear Caches button should not be part of Performance form
parent e129b1e0
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\system\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\system\Form\ClearCacheForm;
use Drupal\system\Form\PerformanceForm;

/**
 * Controller for performance admin.
 */
class PerformanceController extends ControllerBase {

  /**
   * Displays the system performance page.
   *
   * @return array
   *   A render array containing the cache-clear form and performance
   *   configuration form.
   */
  public function build(): array {
    return [
      'cache_clear' => $this->formBuilder()->getForm(ClearCacheForm::class),
      'performance' => $this->formBuilder()->getForm(PerformanceForm::class),
    ];
  }

}
+49 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\system\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Clear caches for this site.
 *
 * @internal
 */
class ClearCacheForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'system_clear_cache';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['clear_cache'] = [
      '#type' => 'details',
      '#title' => $this->t('Clear cache'),
      '#open' => TRUE,
    ];

    $form['clear_cache']['clear'] = [
      '#type' => 'submit',
      '#value' => $this->t('Clear all caches'),
    ];

    return $form;
  }

  /**
   * Clears the caches.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    drupal_flush_all_caches();
    $this->messenger()->addStatus($this->t('Caches cleared.'));
  }

}
+0 −20
Original line number Diff line number Diff line
@@ -104,18 +104,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {

    $config = $this->config('system.performance');

    $form['clear_cache'] = [
      '#type' => 'details',
      '#title' => $this->t('Clear cache'),
      '#open' => TRUE,
    ];

    $form['clear_cache']['clear'] = [
      '#type' => 'submit',
      '#value' => $this->t('Clear all caches'),
      '#submit' => ['::submitCacheClear'],
    ];

    $form['caching'] = [
      '#type' => 'details',
      '#title' => $this->t('Caching'),
@@ -185,12 +173,4 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
  }

  /**
   * Clears the caches.
   */
  public function submitCacheClear(array &$form, FormStateInterface $form_state) {
    drupal_flush_all_caches();
    $this->messenger()->addStatus($this->t('Caches cleared.'));
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ system.logging_settings:
system.performance_settings:
  path: '/admin/config/development/performance'
  defaults:
    _form: '\Drupal\system\Form\PerformanceForm'
    _controller: '\Drupal\system\Controller\PerformanceController::build'
    _title: 'Performance'
  requirements:
    _permission: 'administer site configuration'