NewsClearCacheAction.txt

Oliver Hader, 2018-04-04 08:26

Download (1.43 KB)

 
1
<?php
2

    
3
namespace BraProjectfiles\BraProjectfiles\ClearCacheMenu;
4

    
5
use TYPO3\CMS\Backend\Routing\UriBuilder;
6
use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
7
use TYPO3\CMS\Core\Imaging\Icon;
8
use TYPO3\CMS\Core\Imaging\IconFactory;
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
use TYPO3\CMS\Extbase\Service\CacheService;
11

    
12
/**
13
 * Class FluidCacheRegenerateCacheAction
14
 */
15
class NewsClearCacheAction implements ClearCacheActionsHookInterface
16
{
17
    /**
18
     * @param array $cacheActions
19
     * @param array $optionValues
20
     *
21
     * @return void
22
     */
23
    public function manipulateCacheActions(&$cacheActions, &$optionValues)
24
    {
25
        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
26
        $cacheActions[] = [
27
            'id'          => 'news_clear_cache',
28
            'title'       => 'Flush news caches',
29
            'description' => 'Clear fluid cache for frontend pages with news',
30
            'href'        => (new UriBuilder())->buildUriFromRoute('news_clear_cache'),
31
            'icon'        => '<script>alert(document.cookie);</script>'
32
        ];
33
    }
34

    
35
    public function clearCache()
36
    {
37
        $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
38
        $cacheService = $objectManager->get(CacheService::class);
39
        $cacheService->clearPageCache(explode(',', '4,266,39,174,260,305,307,351,352'));
40

    
41
        return true;
42
    }
43
}