You are here

public function CacheflushApi::clearPresetCache in CacheFlush 8

Based on settings decide witch clear cache function to be called.

Parameters

\Drupal\cacheflush_entity\Entity\CacheflushEntity $entity: Preset id to do clear cache for.

1 call to CacheflushApi::clearPresetCache()
CacheflushApi::clearById in src/Controller/CacheflushApi.php
Clear cache preset by cacheflush entity id.

File

src/Controller/CacheflushApi.php, line 89

Class

CacheflushApi
Returns responses for Cacheflush routes.

Namespace

Drupal\cacheflush\Controller

Code

public function clearPresetCache(CacheflushEntity $entity) {
  $this
    ->checkError($entity);
  $this
    ->moduleHandler()
    ->invokeAll('cacheflush_before_clear', [
    $entity,
  ]);
  $presets = $entity
    ->getData();
  if ($presets) {
    foreach ($presets as $cache) {
      foreach ($cache['functions'] as $value) {
        if (is_callable($value['#name'])) {
          call_user_func_array($value['#name'], $value['#params']);
        }
        else {
          $this
            ->getLogger('CACHEFLUSH')
            ->warning($this
            ->t("Function cannot be called: @name", [
            '@name' => $value['#name'],
          ]));
        }
      }
    }
  }
  $this->messenger
    ->addMessage($this
    ->t("All predefined cache options in @name was cleared.", [
    '@name' => $entity
      ->getTitle(),
  ]));
  $this
    ->moduleHandler()
    ->invokeAll('cacheflush_after_clear', [
    $entity,
  ]);
}