Skip to content

Commit

Permalink
ENH Top page configuration improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Sep 26, 2024
1 parent 3afdc7d commit 552e4dc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
36 changes: 32 additions & 4 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
27 changes: 17 additions & 10 deletions docs/en/02_advanced_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 0 additions & 2 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +90,6 @@ class BaseElement extends DataObject implements CMSPreviewable

private static $extensions = [
Versioned::class,
DataExtension::class,
];

private static $casting = [
Expand Down
2 changes: 0 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,7 +36,6 @@ class ElementalArea extends DataObject

private static $extensions = [
Versioned::class,
DataExtension::class,
];

private static $owns = [
Expand Down

0 comments on commit 552e4dc

Please sign in to comment.