Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Rename TopPage classes #1249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SilverStripe\CMS\Controllers\CMSMain:

SilverStripe\CMS\Model\SiteTree:
extensions:
topPageSiteTreeExtension: DNADesign\Elemental\TopPage\SiteTreeExtension
topPageSiteTreeExtension: DNADesign\Elemental\Extensions\TopPageSiteTreeExtension

SilverStripe\Versioned\VersionedGridFieldItemRequest:
extensions:
Expand Down
4 changes: 2 additions & 2 deletions docs/en/02_advanced_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ above:
```yml
DNADesign\Elemental\Models\BaseElement:
extensions:
topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension
topPageFluentElementExtension: DNADesign\Elemental\Extensions\TopPageFluentElementExtension

DNADesign\Elemental\Models\ElementalArea:
extensions:
topPageDataExtension: DNADesign\Elemental\TopPage\FluentExtension
topPageFluentElementExtension: DNADesign\Elemental\Extensions\TopPageFluentElementExtension
```

These variants will also store the locale of the top page on blocks, which simplifies top page lookup in case the locale
Expand Down
4 changes: 2 additions & 2 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ en:
Summary: Summary
Title: Title
Type: Type
DNADesign\Elemental\TopPage\DataExtension:
DNADesign\Elemental\Extensions\TopPageElementExtension:
has_one_TopPage: 'Top page'
DNADesign\Elemental\TopPage\FluentExtension:
DNADesign\Elemental\Extensions\TopPageFluentElementExtension:
db_TopPageLocale: 'Top page locale'
SilverStripe\CMS\Controllers\CMSPageHistoryController:
PREVIEW: 'Website preview'
4 changes: 2 additions & 2 deletions lang/sl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ sl:
Summary: Povzetek
Title: Naslov
Type: 'Tip gradnika'
DNADesign\Elemental\TopPage\DataExtension:
DNADesign\Elemental\Extensions\TopPageElementExtension:
has_one_TopPage: 'Vrhnja stran'
DNADesign\Elemental\TopPage\FluentExtension:
DNADesign\Elemental\Extensions\TopPageFluentElementExtension
db_TopPageLocale: 'Lokalizacija vrhnje strani '
SilverStripe\CMS\Controllers\CMSPageHistoryController:
PREVIEW: Predogled
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DNADesign\Elemental\TopPage;
namespace DNADesign\Elemental\Extensions;

use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
Expand All @@ -12,22 +12,17 @@
use SilverStripe\View\ViewableData;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Extension;
use SilverStripe\Dev\Deprecation;

/**
* Class DataExtension
*
* Provides a db-cached reference to the top-level page for improved read performance on projects
* with deeply nested block structures. Apply to @see BaseElement and @see ElementalArea.
*
* @property int $TopPageID
* @method SiteTree TopPage()
*
* @extends Extension<BaseElement|ElementalArea|static>
*
* @deprecated 5.4.0 Will be replaced with DNADesign\Elemental\Extensions\TopPageElementExtension
*/
class DataExtension extends Extension
class TopPageElementExtension extends Extension
{
/**
* @config
Expand All @@ -49,22 +44,11 @@ class DataExtension extends Extension
* Global flag which indicates that automatic page determination is enabled or not
* If this is set to a page ID it will be used instead of trying to determine the top page
*
* @see DataExtension::withFixedTopPage()
* @see TopPageElementExtension::withFixedTopPage()
* @var int
*/
private $fixedTopPageID = 0;

public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with DNADesign\Elemental\Extensions\TopPageElementExtension',
Deprecation::SCOPE_CLASS
);
});
}

/**
* Extension point in @see DataObject::onAfterWrite()
*
Expand Down Expand Up @@ -114,7 +98,7 @@ public function getTopPage(): ?SiteTree
return $item;
}

if ($item->hasExtension(DataExtension::class) && $item->TopPageID > 0) {
if ($item->hasExtension(TopPageElementExtension::class) && $item->TopPageID > 0) {
// top page is stored inside data object - just fetch it via cached call
$page = $this->getTopPageFromCachedData((int) $item->TopPageID);

Expand Down Expand Up @@ -151,7 +135,7 @@ public function getTopPage(): ?SiteTree

/**
* Set top page to an object
* If no page is provided as an argument nor as a fixed id via @see DataExtension::withFixedTopPage()
* If no page is provided as an argument nor as a fixed id via @see TopPageElementExtension::withFixedTopPage()
* automatic page determination will be attempted
* Note that this may not always succeed as your model may not be attached to parent object at the time of this call
*
Expand All @@ -162,7 +146,7 @@ public function setTopPage(?SiteTree $page = null): void
{
$owner = $this->owner;

if (!$owner->hasExtension(DataExtension::class)) {
if (!$owner->hasExtension(TopPageElementExtension::class)) {
return;
}

Expand Down Expand Up @@ -233,7 +217,7 @@ protected function getFixedTopPageID(): int
*/
protected function updateTopPage(): void
{
$extension = singleton(SiteTreeExtension::class);
$extension = singleton(TopPageSiteTreeExtension::class);
$extension->addDuplicatedObject($this->owner);
}

Expand All @@ -259,7 +243,7 @@ protected function clearTopPage(): void
/**
* Assigns top page relation based on fixed id
*
* @see DataExtension::withFixedTopPage()
* @see TopPageElementExtension::withFixedTopPage()
*/
protected function assignFixedTopPage(): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DNADesign\Elemental\TopPage;
namespace DNADesign\Elemental\Extensions;

use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
Expand All @@ -9,21 +9,16 @@
use SilverStripe\ORM\Queries\SQLUpdate;
use TractorCow\Fluent\State\FluentState;
use SilverStripe\Forms\FieldList;
use SilverStripe\Dev\Deprecation;

/**
* Class FluentExtension
*
* Use in place of @see DataExtension if you use the Fluent module for page localisation.
* Use in place of @see TopPageElementExtension if you use the Fluent module for page localisation.
*
* @link https://github.com/tractorcow-farm/silverstripe-fluent
* @property string $TopPageLocale
*
* @extends DataExtension<DataObject&static>
*
* @deprecated 5.4.0 Will be replaced with DNADesign\Elemental\Extensions\TopPageFluentElementExtension
* @extends TopPageElementExtension<DataObject&static>
*/
class FluentExtension extends DataExtension
class TopPageFluentElementExtension extends TopPageElementExtension
{
/**
* @var array
Expand All @@ -32,17 +27,6 @@ class FluentExtension extends DataExtension
'TopPageLocale' => 'Varchar',
];

public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with DNADesign\Elemental\Extensions\TopPageFluentElementExtension',
Deprecation::SCOPE_CLASS
);
});
}

protected function updateCMSFields(FieldList $fields)
{
$fields->removeByName('TopPageID');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
<?php

namespace DNADesign\Elemental\TopPage;
namespace DNADesign\Elemental\Extensions;

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Core\Extension;
use SilverStripe\Dev\Deprecation;

/**
* Class SiteTreeExtension
*
* This extension must be present on pagetypes that need to support Elemental TopPage functionality.
* It can be applied directly to Page, as it only takes effect in the presence of a ElementalArea.
*
* @extends Extension<SiteTree&static>
*
* @deprecated 5.4.0 Will be replaced with DNADesign\Elemental\Extensions\TopPageSiteTreeExtension
*/
class SiteTreeExtension extends Extension
class TopPageSiteTreeExtension extends Extension
{
/**
* List of pages currently undergoing duplication
Expand All @@ -35,17 +30,6 @@ class SiteTreeExtension extends Extension
*/
protected $duplicatedObjects = [];

public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with DNADesign\Elemental\Extensions\TopPageSiteTreeExtension',
Deprecation::SCOPE_CLASS
);
});
}

/**
* Extension point in @see DataObject::onAfterWrite()
*
Expand Down Expand Up @@ -106,7 +90,7 @@ public function getDuplicationKey(): ?string
*/
public function addDuplicatedObject(DataObject $object): void
{
if (!$object->hasExtension(DataExtension::class)) {
if (!$object->hasExtension(TopPageElementExtension::class)) {
return;
}

Expand Down Expand Up @@ -143,7 +127,7 @@ protected function getDuplicatedPageKey(): ?string
}

/**
* @param SiteTree|SiteTreeExtension $original
* @param SiteTree|TopPageSiteTreeExtension $original
*/
protected function initDuplication(SiteTree $original): void
{
Expand Down Expand Up @@ -206,7 +190,7 @@ protected function processDuplicationFromOriginal(): void
}

/**
* @param SiteTree|SiteTreeExtension $original
* @param SiteTree|TopPageSiteTreeExtension $original
* @throws ValidationException
*/
protected function writeDuplication(SiteTree $original): void
Expand All @@ -222,7 +206,7 @@ protected function writeDuplication(SiteTree $original): void
if (array_key_exists($key, $this->duplicatedObjects ?? [])) {
$objects = $this->duplicatedObjects[$key];

/** @var DataObject|DataExtension $object */
/** @var DataObject|TopPageElementExtension $object */
foreach ($objects as $object) {
// attach current page ID to the object
$object->setTopPage($this->owner);
Expand Down Expand Up @@ -257,7 +241,7 @@ protected function setTopPageForElementalArea(): void
return;
}

if (!$area->hasExtension(DataExtension::class)) {
if (!$area->hasExtension(TopPageElementExtension::class)) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use DNADesign\Elemental\Controllers\ElementController;
use DNADesign\Elemental\Forms\TextCheckboxGroupField;
use DNADesign\Elemental\Services\ReorderElements;
use DNADesign\Elemental\TopPage\DataExtension;
use DNADesign\Elemental\Extensions\TopPageElementExtension;
use Exception;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Model\SiteTree;
Expand Down Expand Up @@ -88,7 +88,7 @@ class BaseElement extends DataObject implements CMSPreviewable

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

private static $casting = [
Expand Down
4 changes: 2 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DNADesign\Elemental\Controllers\ElementController;
use DNADesign\Elemental\Extensions\ElementalAreasExtension;
use DNADesign\Elemental\TopPage\DataExtension;
use DNADesign\Elemental\Extensions\TopPageElementExtension;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\TestOnly;
Expand Down Expand Up @@ -37,7 +37,7 @@ class ElementalArea extends DataObject

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

private static $owns = [
Expand Down
21 changes: 11 additions & 10 deletions tests/TopPage/TopPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\TopPage;
use Page;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataObject;
use DNADesign\Elemental\Extensions\TopPageElementExtension;
use DNADesign\Elemental\Extensions\TopPageSiteTreeExtension;

class TopPageTest extends SapphireTest
{
Expand All @@ -29,13 +30,13 @@ class TopPageTest extends SapphireTest
ElementalPageExtension::class,
],
Page::class => [
TopPage\SiteTreeExtension::class,
TopPageSiteTreeExtension::class,
],
ElementalArea::class => [
TopPage\DataExtension::class,
TopPageElementExtension::class,
],
BaseElement::class => [
TopPage\DataExtension::class,
TopPageElementExtension::class,
],
TestList::class => [
ElementalAreasExtension::class,
Expand Down Expand Up @@ -65,10 +66,10 @@ public function testTestGetTopPage(
string $objectIdentifier,
string $objectClass
): void {
/** @var Page|TopPage\SiteTreeExtension $content */
/** @var Page|TopPageSiteTreeExtension $content */
$page = $this->objFromFixture($pageClass, $pageIdentifier);

/** @var DataObject|TopPage\DataExtension $object */
/** @var DataObject|TopPageElementExtension $object */
$object = $this->objFromFixture($objectClass, $objectIdentifier);

$topPage = $object->getTopPage();
Expand All @@ -90,10 +91,10 @@ public function testTestUpdateTopPageEmptyCache(
string $objectIdentifier,
string $objectClass
): void {
/** @var Page|TopPage\SiteTreeExtension $content */
/** @var Page|TopPageSiteTreeExtension $content */
$page = $this->objFromFixture($pageClass, $pageIdentifier);

/** @var DataObject|TopPage\DataExtension $object */
/** @var DataObject|TopPageElementExtension $object */
$object = $this->objFromFixture($objectClass, $objectIdentifier);
$initialObj = $objectClass::get()->sort('ID', 'DESC');

Expand All @@ -119,7 +120,7 @@ public function testNewPage(): void
$page->Title = 'New page test';
$page->write();

/** @var ElementalArea|TopPage\DataExtension $area */
/** @var ElementalArea|TopPageElementExtension $area */
$area = $page->ElementalArea();
$this->assertEquals((int) $page->ID, (int) $area->TopPageID);
}
Expand All @@ -140,7 +141,7 @@ public function testNewBlock(bool $populateTopPage): void
/** @var ElementalArea $area */
$area = $this->objFromFixture(ElementalArea::class, 'area3');

/** @var TestContent|TopPage\DataExtension $content */
/** @var TestContent|TopPageElementExtension $content */
$content = TestContent::create();
$content->Title = 'Fresh block';

Expand Down
Loading