silverstripe-webpack/app/src/Pages/PageController.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2018-04-21 06:29:32 +02:00
<?php
// vendor/silverstripe/errorpage/src/ErrorPageController.php
// extends global PageController class
2021-03-14 21:45:35 +01:00
//namespace App\Pages;
2024-02-02 17:21:05 +01:00
use A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx;
2018-04-21 06:29:32 +02:00
use SilverStripe\CMS\Controllers\ContentController;
2024-01-25 14:09:11 +01:00
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\View\SSViewer;
2018-04-21 06:29:32 +02:00
2022-05-10 12:36:40 +02:00
/**
* Class \PageController
*
2023-08-04 00:28:22 +02:00
* @property \Page $dataRecord
2022-05-10 12:36:40 +02:00
* @method \Page data()
* @mixin \Page
2024-01-25 14:09:11 +01:00
* @mixin \A2nt\CMSNiceties\Extensions\PageControllerEx
2024-04-22 14:43:32 +02:00
* @mixin \A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx
2022-05-10 12:36:40 +02:00
*/
2018-04-21 06:29:32 +02:00
class PageController extends ContentController
{
2024-01-25 14:09:11 +01:00
private static $graphql_resources = [];
private static $ajax_resources = [];
2024-04-22 16:25:52 +02:00
public function ElementalArea()
{
return $this->dataRecord->ElementalArea();
}
2024-01-25 14:09:11 +01:00
public function getViewer($action)
{
// Manually set templates should be dealt with by Controller::getViewer()
if (!empty($this->templates[$action])
|| !empty($this->templates['index'])
|| $this->template
) {
return parent::getViewer($action);
}
// Prepare action for template search
$action = $action === 'index' ? '' : '_' . $action;
$templatesFound = [];
// Find templates for the record + action together - e.g. Page_action.ss
if ($this->dataRecord instanceof SiteTree) {
$templatesFound[] = $this->dataRecord->getViewerTemplates($action);
}
// Find templates for the controller + action together - e.g. PageController_action.ss
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action, Controller::class);
// Find templates for the record without an action - e.g. Page.ss
if ($this->dataRecord instanceof SiteTree) {
$templatesFound[] = $this->dataRecord->getViewerTemplates();
}
// Find the templates for the controller without an action - e.g. PageController.ss
$templatesFound[] = SSViewer::get_templates_by_class(static::class, "", Controller::class);
$tpls = array_merge(...$templatesFound);
// inject AJAX processing
if (Director::is_ajax()) {
2024-02-02 17:21:05 +01:00
return AjaxControllerEx::processAJAX($tpls);
2024-01-25 14:09:11 +01:00
}
return SSViewer::create($tpls);
}
protected function prepareResponse($response)
{
parent::prepareResponse($response);
// inject AJAX processing
if (Director::is_ajax()) {
$response = $this->getResponse();
$this->prepareAjaxResponse($response);
}
}
2018-04-21 06:29:32 +02:00
}