|
<?php
|
|
|
|
namespace Foobar\Sitepackage\Hooks\Backend;
|
|
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
|
use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
|
use TYPO3\CMS\Core\Http\JsonResponse;
|
|
use TYPO3\CMS\Core\Http\RequestFactory;
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
use TYPO3\CMS\Core\Http\Response;
|
|
|
|
/**
|
|
* Class ClearCacheActionsHook
|
|
*
|
|
* @package BraProjectfiles\Hooks\Backend\Toolbar
|
|
*/
|
|
class FlushNodeCacheHook implements ClearCacheActionsHookInterface
|
|
{
|
|
|
|
/**
|
|
* @var UriBuilder $uriBuilder
|
|
*/
|
|
protected $uriBuilder;
|
|
|
|
/**
|
|
* @var BackendUserAuthentication
|
|
*/
|
|
protected $backendUser;
|
|
|
|
/**
|
|
* ClearCacheActionsHook constructor.
|
|
*
|
|
* @param UriBuilder|null $uriBuilder
|
|
* @param BackendUserAuthentication|null $backendUser
|
|
*/
|
|
public function __construct(UriBuilder $uriBuilder = null, BackendUserAuthentication $backendUser = null)
|
|
{
|
|
$this->uriBuilder = $uriBuilder ?? GeneralUtility::makeInstance(UriBuilder::class);
|
|
$this->backendUser = $backendUser ?? $GLOBALS['BE_USER'];
|
|
}
|
|
|
|
/**
|
|
* @param array $cacheActions
|
|
* @param array $optionValues
|
|
*
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
|
|
*/
|
|
public function manipulateCacheActions(&$cacheActions, &$optionValues)
|
|
{
|
|
if (!$this->backendUser->isAdmin()) {
|
|
return;
|
|
}
|
|
|
|
$href = $this->uriBuilder->buildUriFromRoute('ajax_foobar');
|
|
|
|
$optionValues[] = 'clearFoobarCache';
|
|
$cacheActions[] = [
|
|
'id' => 'clearFoobarCache',
|
|
'title' => 'Title',
|
|
'description' => 'Description',
|
|
'href' => $href,
|
|
'iconIdentifier' => 'foobar-flush'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param ServerRequestInterface $request
|
|
* @param ResponseInterface $response
|
|
*
|
|
* @return ResponseInterface
|
|
*/
|
|
public function myFunctionName(ServerRequestInterface $request): ResponseInterface
|
|
{
|
|
|
|
$content = [
|
|
'success' => true
|
|
];
|
|
|
|
$response = new Response();
|
|
$response->getBody()->write(json_encode($content));
|
|
return $response;
|
|
}
|
|
}
|
|
|