You are here

function pcb_form_system_performance_settings_submit in Permanent Cache Bin 8.2

Same name and namespace in other branches
  1. 8 pcb.module \pcb_form_system_performance_settings_submit()

Submit callback for clearing specific permanent cache bins.

1 string reference to 'pcb_form_system_performance_settings_submit'
pcb_form_system_performance_settings_alter in ./pcb.module
Implements hook_form_FORM_ID_alter().

File

./pcb.module, line 49
Module file for pcb.

Code

function pcb_form_system_performance_settings_submit(array &$form, FormStateInterface $form_state) {
  $element = $form_state
    ->getTriggeringElement();
  $bin = $element['#name'] ?? '';
  if (empty($bin)) {
    return;
  }
  $messenger = \Drupal::messenger();
  try {
    \Drupal::service('cache.' . $bin)
      ->deleteAllPermanent();
    $messenger
      ->addMessage(t('Flushed cache for @bin.', [
      '@bin' => $bin,
    ]));
  } catch (\Exception $e) {
    $messenger
      ->addMessage($e
      ->getMessage(), MessengerInterface::TYPE_ERROR);
  }
}