ClearCacheForm.php

Same filename and directory in other branches
  1. 10 core/modules/system/src/Form/ClearCacheForm.php

Namespace

Drupal\system\Form

File

core/modules/system/src/Form/ClearCacheForm.php

View source
<?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.'));
    }

}

Classes

Title Deprecated Summary
ClearCacheForm Clear caches for this site.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.