abstract class RequestHandlerBase in Panels 8.3
Same name and namespace in other branches
- 8.4 panels_ipe/src/Helpers/RequestHandlerBase.php \Drupal\panels_ipe\Helpers\RequestHandlerBase
Hierarchy
- class \Drupal\panels_ipe\Helpers\RequestHandlerBase implements RequestHandlerInterface
Expanded class hierarchy of RequestHandlerBase
File
- panels_ipe/
src/ Helpers/ RequestHandlerBase.php, line 18
Namespace
Drupal\panels_ipe\HelpersView source
abstract class RequestHandlerBase implements RequestHandlerInterface {
/**
* @var int */
private $responseStatusCode = 200;
/**
* @var array */
private $response = [];
/**
* @var \Drupal\user\SharedTempStore */
private $tempStore;
/**
* @var \Drupal\panels\Storage\PanelsStorageManagerInterface */
private $panelsStore;
/**
* @var \Drupal\Core\Extension\ModuleHandlerInterface */
private $moduleHandler;
public function __construct(ModuleHandlerInterface $module_handler, PanelsStorageManagerInterface $panels_store, SharedTempStore $temp_store) {
$this->moduleHandler = $module_handler;
$this->panelsStore = $panels_store;
$this->tempStore = $temp_store;
}
/**
* @inheritdoc
*/
public function handleRequest(PanelsDisplayVariant $panels_display, Request $request, $save_to_temp_store = FALSE) {
$this
->setResponse([]);
try {
$this
->handle($panels_display, self::decodeRequest($request), $save_to_temp_store);
} catch (EmptyRequestContentException $e) {
$this
->setResponse([
'success' => FALSE,
], 400);
}
}
/**
* Handles the decoded request by making some change to the Panels Display.
*
* @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
* @param mixed $decoded_request
* @param bool $save_to_temp_store
*
* @throws \Drupal\panels_ipe\Exception\EmptyRequestContentException
*/
protected abstract function handle(PanelsDisplayVariant $panels_display, $decoded_request, $save_to_temp_store = FALSE);
/**
* Attempts to decode the incoming request's content as JSON.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return mixed
*
* @throws \Drupal\panels_ipe\Exception\EmptyRequestContentException
*/
protected static function decodeRequest(Request $request) {
if (empty($request
->getContent())) {
throw new EmptyRequestContentException();
}
return Json::decode($request
->getContent());
}
/**
* Helper function for invoking hooks for all enabled modules.
*
* @param $hook
* @param array $arguments
*/
protected function invokeHook($hook, array $arguments) {
$this->moduleHandler
->invokeAll($hook, $arguments);
}
/**
* Deletes TempStore and saves the current Panels display.
*
* @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
* The Panels display to be saved.
*
* @throws \Drupal\user\TempStoreException
* If there are any issues manipulating the entry in the temp store.
*/
protected function savePanelsDisplay(PanelsDisplayVariant $panels_display) {
$this
->deletePanelsDisplayTempStore($panels_display);
$this->panelsStore
->save($panels_display);
}
/**
* Saves the given Panels Display to TempStore.
*
* @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
*
* @throws \Drupal\user\TempStoreException
*/
protected function savePanelsDisplayToTempStore(PanelsDisplayVariant $panels_display) {
$this->tempStore
->set($panels_display
->id(), $panels_display
->getConfiguration());
}
/**
* Deletes the given Panels Display from TempStore.
*
* @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
*
* @throws \Drupal\user\TempStoreException
*/
protected function deletePanelsDisplayTempStore(PanelsDisplayVariant $panels_display) {
$this->tempStore
->delete($panels_display
->id());
}
/**
* Returns the current response data as a JSON Response.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function getJsonResponse() {
return new JsonResponse($this->response, $this->responseStatusCode);
}
/**
* Updates our response and response status code properties.
*
* @param array $response
* @param int $response_status_code
*/
protected function setResponse(array $response, $response_status_code = 200) {
$this->response = $response;
$this->responseStatusCode = $response_status_code;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RequestHandlerBase:: |
private | property | @var \Drupal\Core\Extension\ModuleHandlerInterface | |
RequestHandlerBase:: |
private | property | @var \Drupal\panels\Storage\PanelsStorageManagerInterface | |
RequestHandlerBase:: |
private | property | @var array | |
RequestHandlerBase:: |
private | property | @var int | |
RequestHandlerBase:: |
private | property | @var \Drupal\user\SharedTempStore | |
RequestHandlerBase:: |
protected static | function | Attempts to decode the incoming request's content as JSON. | |
RequestHandlerBase:: |
protected | function | Deletes the given Panels Display from TempStore. | |
RequestHandlerBase:: |
public | function |
Returns the current response data as a JSON Response. Overrides RequestHandlerInterface:: |
|
RequestHandlerBase:: |
abstract protected | function | Handles the decoded request by making some change to the Panels Display. | 2 |
RequestHandlerBase:: |
public | function |
@inheritdoc Overrides RequestHandlerInterface:: |
|
RequestHandlerBase:: |
protected | function | Helper function for invoking hooks for all enabled modules. | |
RequestHandlerBase:: |
protected | function | Deletes TempStore and saves the current Panels display. | |
RequestHandlerBase:: |
protected | function | Saves the given Panels Display to TempStore. | |
RequestHandlerBase:: |
protected | function | Updates our response and response status code properties. | |
RequestHandlerBase:: |
public | function |