From 552e4dc540a1f5b3e478531a8e70e4db486b09c9 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Fri, 27 Sep 2024 10:15:15 +1200 Subject: [PATCH] ENH Top page configuration improvements. --- _config/config.yml | 36 ++++++++++++++++++++++++++++++++---- docs/en/02_advanced_setup.md | 27 +++++++++++++++++---------- src/Models/BaseElement.php | 2 -- src/Models/ElementalArea.php | 2 -- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/_config/config.yml b/_config/config.yml index 79d8ecb3..e41af980 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -24,10 +24,6 @@ SilverStripe\CMS\Controllers\CMSMain: extensions: - DNADesign\Elemental\Extensions\ElementalCMSMainExtension -SilverStripe\CMS\Model\SiteTree: - extensions: - topPageSiteTreeExtension: DNADesign\Elemental\TopPage\SiteTreeExtension - SilverStripe\Versioned\VersionedGridFieldItemRequest: extensions: - 'DNADesign\Elemental\Extensions\GridFieldDetailFormItemRequestExtension' @@ -39,3 +35,35 @@ Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler: SilverStripe\Core\Injector\Injector: SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search: class: DNADesign\Elemental\Controllers\ElementSiteTreeFilterSearch + +--- +Name: elemental-top-page-default +--- + +DNADesign\Elemental\Models\BaseElement: + extensions: + topPageDataExtension: DNADesign\Elemental\TopPage\DataExtension + +DNADesign\Elemental\Models\ElementalArea: + extensions: + topPageDataExtension: DNADesign\Elemental\TopPage\DataExtension + +SilverStripe\CMS\Model\SiteTree: + extensions: + topPageSiteTreeExtension: DNADesign\Elemental\TopPage\SiteTreeExtension + +--- +Name: elemental-top-page-fluent +After: + - elemental-top-page-default +Only: + moduleexists: 'tractorcow/silverstripe-fluent' +--- + +DNADesign\Elemental\Models\BaseElement: + extensions: + topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension + +DNADesign\Elemental\Models\ElementalArea: + extensions: + topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension diff --git a/docs/en/02_advanced_setup.md b/docs/en/02_advanced_setup.md index 87c8114f..84ac3aef 100644 --- a/docs/en/02_advanced_setup.md +++ b/docs/en/02_advanced_setup.md @@ -444,21 +444,28 @@ directly on the block as a performance enhancement for this query. A set of exte of the box for elements on pages. You can use `$TopPage` in your template to get access to the page, which is more performant than using `$Page`. -If your project makes use of the Fluent module, it is recommended to use the following extensions in place of the ones -above: +If your project makes use of the Fluent module, this feature will automatically replace `DNADesign\Elemental\TopPage\DataExtension` with `DNADesign\Elemental\TopPage\FluentExtension`. + +These variants will also store the locale of the top page on blocks, which simplifies top page lookup in case the locale +is unknown at the time of page lookup from block context. + +The page reference on the blocks can also be useful for maintenance dev tasks, as it's easy to identify which blocks +belong to which pages in which locale. + +In case you need to further customise this setup with your own extension override, one way how to do this is shown below: ```yml +--- +Name: my-elemental-config +After: + - elemental-top-page-fluent +--- + DNADesign\Elemental\Models\BaseElement: extensions: - topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension + topPageDataExtension: App\MyExtension DNADesign\Elemental\Models\ElementalArea: extensions: - topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension + topPageDataExtension: App\MyExtension ``` - -These variants will also store the locale of the top page on blocks, which simplifies top page lookup in case the locale -is unknown at the time of page lookup from block context. - -The page reference on the blocks can also be useful for maintenance dev tasks, as it's easy to identify which blocks -belong to which pages in which locale. diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index f26fa9f7..d66be164 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -6,7 +6,6 @@ use DNADesign\Elemental\Forms\TextCheckboxGroupField; use DNADesign\Elemental\ORM\FieldType\DBObjectType; use DNADesign\Elemental\Services\ReorderElements; -use DNADesign\Elemental\TopPage\DataExtension; use Exception; use SilverStripe\CMS\Controllers\CMSPageEditController; use SilverStripe\CMS\Model\SiteTree; @@ -91,7 +90,6 @@ class BaseElement extends DataObject implements CMSPreviewable private static $extensions = [ Versioned::class, - DataExtension::class, ]; private static $casting = [ diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 183064c8..2a6a8d8f 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -4,7 +4,6 @@ use DNADesign\Elemental\Controllers\ElementController; use DNADesign\Elemental\Extensions\ElementalAreasExtension; -use DNADesign\Elemental\TopPage\DataExtension; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\TestOnly; @@ -37,7 +36,6 @@ class ElementalArea extends DataObject private static $extensions = [ Versioned::class, - DataExtension::class, ]; private static $owns = [