From fe9088698fd98de087fe50823fb28844f5ff950a Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 26 Sep 2024 16:42:34 +1200 Subject: [PATCH] ENH Improve type safety to support refactored template layer --- code/Controllers/ContentController.php | 22 +++----- code/Model/SiteTree.php | 4 +- tests/behat/src/ThemeContext.php | 2 +- .../php/Controllers/ContentControllerTest.php | 31 ++++++---- .../DummyTemplateContentController.php | 15 +++++ .../DummyTemplateEngine.php | 56 +++++++++++++++++++ 6 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 tests/php/Controllers/ContentControllerTest/DummyTemplateContentController.php create mode 100644 tests/php/Controllers/ContentControllerTest/DummyTemplateEngine.php diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index f5ed8ba7..36ac4b97 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -289,14 +289,6 @@ class ContentController extends Controller return new ArrayList($visible); } - /** - * @return ArrayList - */ - public function Menu($level) - { - return $this->getMenu($level); - } - /** * Returns the default log-in form. * @@ -413,23 +405,23 @@ HTML; $action = $action === 'index' ? '' : '_' . $action; $templatesFound = []; - // Find templates for the record + action together - e.g. Page_action.ss + // Find templates for the record + action together - e.g. Page_action 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 controller + action together - e.g. PageController_action + $templatesFound[] = SSViewer::get_templates_by_class(static::class, $action ?? '', Controller::class); - // Find templates for the record without an action - e.g. Page.ss + // Find templates for the record without an action - e.g. Page 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); + // Find the templates for the controller without an action - e.g. PageController + $templatesFound[] = SSViewer::get_templates_by_class(static::class, '', Controller::class); $templates = array_merge(...$templatesFound); - return SSViewer::create($templates); + return SSViewer::create($templates, $this->getTemplateEngine()); } } diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 2ee8e6b1..4d053e5f 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -1454,7 +1454,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi $tags['title'] = [ 'tag' => 'title', - 'content' => $this->obj('Title')->forTemplate() + 'content' => $this->obj('Title')?->forTemplate() ]; $generator = $this->getGenerator(); @@ -1601,7 +1601,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi $tagString = implode("\n", $tags); if ($this->ExtraMeta) { - $tagString .= $this->obj('ExtraMeta')->forTemplate(); + $tagString .= $this->obj('ExtraMeta')?->forTemplate(); } $this->extend('updateMetaTags', $tagString); diff --git a/tests/behat/src/ThemeContext.php b/tests/behat/src/ThemeContext.php index ead1f826..3da77ee2 100644 --- a/tests/behat/src/ThemeContext.php +++ b/tests/behat/src/ThemeContext.php @@ -33,7 +33,7 @@ class ThemeContext implements Context } /** - * Create a template within a test theme + * Create a template within a test theme. Only ss templates are supported. * * @Given /^a template "(?