From 753fb4a65e8978b2328c8c16840d5652d9f1bdad Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 4 Sep 2024 12:24:43 +1200 Subject: [PATCH] API Rename TopPage classes --- _config/config.yml | 2 +- docs/en/02_advanced_setup.md | 4 +-- lang/en.yml | 4 +-- lang/sl.yml | 4 +-- .../TopPageElementExtension.php} | 32 +++++-------------- .../TopPageFluentElementExtension.php} | 24 +++----------- .../TopPageSiteTreeExtension.php} | 30 ++++------------- src/Models/BaseElement.php | 4 +-- src/Models/ElementalArea.php | 4 +-- tests/TopPage/TopPageTest.php | 21 ++++++------ 10 files changed, 41 insertions(+), 88 deletions(-) rename src/{TopPage/DataExtension.php => Extensions/TopPageElementExtension.php} (90%) rename src/{TopPage/FluentExtension.php => Extensions/TopPageFluentElementExtension.php} (67%) rename src/{TopPage/SiteTreeExtension.php => Extensions/TopPageSiteTreeExtension.php} (87%) diff --git a/_config/config.yml b/_config/config.yml index 27baa5f2..9241f6e4 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -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: diff --git a/docs/en/02_advanced_setup.md b/docs/en/02_advanced_setup.md index 94e11440..e20128bd 100644 --- a/docs/en/02_advanced_setup.md +++ b/docs/en/02_advanced_setup.md @@ -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 diff --git a/lang/en.yml b/lang/en.yml index 13f5399f..7d4059a8 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -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' diff --git a/lang/sl.yml b/lang/sl.yml index 74fb74b0..eb357345 100644 --- a/lang/sl.yml +++ b/lang/sl.yml @@ -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 diff --git a/src/TopPage/DataExtension.php b/src/Extensions/TopPageElementExtension.php similarity index 90% rename from src/TopPage/DataExtension.php rename to src/Extensions/TopPageElementExtension.php index 905f9306..7a8c99d1 100644 --- a/src/TopPage/DataExtension.php +++ b/src/Extensions/TopPageElementExtension.php @@ -1,6 +1,6 @@ - * - * @deprecated 5.4.0 Will be replaced with DNADesign\Elemental\Extensions\TopPageElementExtension */ -class DataExtension extends Extension +class TopPageElementExtension extends Extension { /** * @config @@ -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() * @@ -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); @@ -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 * @@ -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; } @@ -233,7 +217,7 @@ protected function getFixedTopPageID(): int */ protected function updateTopPage(): void { - $extension = singleton(SiteTreeExtension::class); + $extension = singleton(TopPageSiteTreeExtension::class); $extension->addDuplicatedObject($this->owner); } @@ -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 { diff --git a/src/TopPage/FluentExtension.php b/src/Extensions/TopPageFluentElementExtension.php similarity index 67% rename from src/TopPage/FluentExtension.php rename to src/Extensions/TopPageFluentElementExtension.php index 076171c3..c2f19c1a 100644 --- a/src/TopPage/FluentExtension.php +++ b/src/Extensions/TopPageFluentElementExtension.php @@ -1,6 +1,6 @@ - * - * @deprecated 5.4.0 Will be replaced with DNADesign\Elemental\Extensions\TopPageFluentElementExtension + * @extends TopPageElementExtension */ -class FluentExtension extends DataExtension +class TopPageFluentElementExtension extends TopPageElementExtension { /** * @var array @@ -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'); diff --git a/src/TopPage/SiteTreeExtension.php b/src/Extensions/TopPageSiteTreeExtension.php similarity index 87% rename from src/TopPage/SiteTreeExtension.php rename to src/Extensions/TopPageSiteTreeExtension.php index 58e2e974..1b568233 100644 --- a/src/TopPage/SiteTreeExtension.php +++ b/src/Extensions/TopPageSiteTreeExtension.php @@ -1,25 +1,20 @@ - * - * @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 @@ -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() * @@ -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; } @@ -143,7 +127,7 @@ protected function getDuplicatedPageKey(): ?string } /** - * @param SiteTree|SiteTreeExtension $original + * @param SiteTree|TopPageSiteTreeExtension $original */ protected function initDuplication(SiteTree $original): void { @@ -206,7 +190,7 @@ protected function processDuplicationFromOriginal(): void } /** - * @param SiteTree|SiteTreeExtension $original + * @param SiteTree|TopPageSiteTreeExtension $original * @throws ValidationException */ protected function writeDuplication(SiteTree $original): void @@ -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); @@ -257,7 +241,7 @@ protected function setTopPageForElementalArea(): void return; } - if (!$area->hasExtension(DataExtension::class)) { + if (!$area->hasExtension(TopPageElementExtension::class)) { return; } diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 319381a7..0822fa6e 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -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; @@ -88,7 +88,7 @@ class BaseElement extends DataObject implements CMSPreviewable private static $extensions = [ Versioned::class, - DataExtension::class, + TopPageElementExtension::class, ]; private static $casting = [ diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 3ef48057..9c450ed0 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -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; @@ -37,7 +37,7 @@ class ElementalArea extends DataObject private static $extensions = [ Versioned::class, - DataExtension::class, + TopPageElementExtension::class, ]; private static $owns = [ diff --git a/tests/TopPage/TopPageTest.php b/tests/TopPage/TopPageTest.php index 1026883c..f898be1a 100644 --- a/tests/TopPage/TopPageTest.php +++ b/tests/TopPage/TopPageTest.php @@ -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 { @@ -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, @@ -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(); @@ -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'); @@ -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); } @@ -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';