From 344a7c548d4f80c773b79522f135f2115f24415e Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 29 Aug 2024 13:54:17 +1200 Subject: [PATCH] API Replace Extension subclasses --- code/Controllers/CMSMain.php | 2 - code/Model/SiteTree.php | 3 - code/Model/SiteTreeExtension.php | 106 ------------------ code/Model/SiteTreeLinkTracking.php | 6 +- .../behat/features/insert-anchor-link.feature | 2 +- .../ModuleIconExtension.php | 4 +- tests/php/Model/SiteTreeBacklinksTest_DOD.php | 4 +- .../Model/SiteTreeLinkTracking_Extension.php | 4 +- .../SiteTreeTest_AdminDeniedExtension.php | 4 +- tests/php/Model/SiteTreeTest_Extension.php | 4 +- tests/php/Model/SiteTreeTest_ExtensionA.php | 4 +- tests/php/Model/SiteTreeTest_ExtensionB.php | 4 +- .../Model/VirtualPageTest_PageExtension.php | 4 +- 13 files changed, 20 insertions(+), 131 deletions(-) delete mode 100644 code/Model/SiteTreeExtension.php diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 64720b764d..375c082777 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -1833,8 +1833,6 @@ public function save(array $data, Form $form): HTTPResponse } /** - * @uses LeftAndMainExtension->augmentNewSiteTreeItem() - * * @param int|string $id * @param bool $setID * @return mixed|DataObject diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 348365e9c1..45c6dd86ad 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -1137,7 +1137,6 @@ public function canAddChildren($member = null) * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups * - * @uses DataExtension->canView() * @uses ViewerGroups() * * @param Member $member @@ -1284,7 +1283,6 @@ public function canDelete($member = null) * Use {@link canAddChildren()} to control behaviour of creating children under this page. * * @uses $can_create - * @uses DataExtension->canCreate() * * @param Member $member * @param array $context Optional array which may contain ['Parent' => $parentObj] @@ -1341,7 +1339,6 @@ public function canCreate($member = null, $context = []) * * @uses canView() * @uses EditorGroups() - * @uses DataExtension->canEdit() * * @param Member $member Set to false if you want to explicitly test permissions without a valid user (useful for * unit tests) diff --git a/code/Model/SiteTreeExtension.php b/code/Model/SiteTreeExtension.php deleted file mode 100644 index f3260e77b0..0000000000 --- a/code/Model/SiteTreeExtension.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @deprecated 5.3.0 Subclass SilverStripe\Core\Extension\Extension instead - */ -abstract class SiteTreeExtension extends DataExtension -{ - public function __construct() - { - // Wrapping with Deprecation::withNoReplacement() to avoid triggering deprecation notices - // as we are unable to update existing subclasses of this class until a new major - // unless we add in the pointless empty methods that are in this class - Deprecation::withNoReplacement(function () { - $class = Extension::class; - Deprecation::notice('5.3.0', "Subclass $class instead", Deprecation::SCOPE_CLASS); - }); - parent::__construct(); - } - - /** - * Hook called before the page's {@link Versioned::publishSingle()} action is completed - * - * @param SiteTree &$original The current Live SiteTree record prior to publish - */ - protected function onBeforePublish(&$original) - { - } - - /** - * Hook called after the page's {@link Versioned::publishSingle()} action is completed - * - * @param SiteTree &$original The current Live SiteTree record prior to publish - */ - protected function onAfterPublish(&$original) - { - } - - /** - * Hook called before the page's {@link Versioned::doUnpublish()} action is completed - */ - protected function onBeforeUnpublish() - { - } - - - /** - * Hook called after the page's {@link SiteTree::doUnpublish()} action is completed - */ - protected function onAfterUnpublish() - { - } - - /** - * Hook called to determine if a user may add children to this SiteTree object - * - * @see SiteTree::canAddChildren() - * - * @param Member $member The member to check permission against, or the currently - * logged in user - * @return boolean|null Return false to deny rights, or null to yield to default - */ - protected function canAddChildren($member) - { - } - - /** - * Hook called to determine if a user may publish this SiteTree object - * - * @see SiteTree::canPublish() - * - * @param Member $member The member to check permission against, or the currently - * logged in user - * @return boolean|null Return false to deny rights, or null to yield to default - */ - protected function canPublish($member) - { - } - - /** - * Hook called to modify the $base url of this page, with a given $action, - * before {@link SiteTree::RelativeLink()} calls {@link Controller::join_links()} - * on the $base and $action - * - * @param string &$link The URL of this page relative to siteroot including - * the action - * @param string $base The URL of this page relative to siteroot, not including - * the action - * @param string|boolean $action The action or subpage called on this page. - * (Legacy support) If this is true, then do not reduce the 'home' urlsegment - * to an empty link - */ - protected function updateRelativeLink(&$link, $base, $action) - { - } -} diff --git a/code/Model/SiteTreeLinkTracking.php b/code/Model/SiteTreeLinkTracking.php index bfc26976a7..04385714f2 100644 --- a/code/Model/SiteTreeLinkTracking.php +++ b/code/Model/SiteTreeLinkTracking.php @@ -6,12 +6,12 @@ use SilverStripe\Assets\Shortcodes\FileLinkTracking; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormScaffolder; -use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\ManyManyThroughList; use SilverStripe\Versioned\Versioned; use SilverStripe\View\Parsers\HTMLValue; +use SilverStripe\Core\Extension; /** * Adds tracking of links in any HTMLText fields which reference SiteTree or File items. @@ -29,9 +29,9 @@ * @property DataObject|SiteTreeLinkTracking $owner * @method ManyManyThroughList LinkTracking() * - * @extends DataExtension + * @extends Extension */ -class SiteTreeLinkTracking extends DataExtension +class SiteTreeLinkTracking extends Extension { /** * @var SiteTreeLinkTracking_Parser diff --git a/tests/behat/features/insert-anchor-link.feature b/tests/behat/features/insert-anchor-link.feature index de9fa1f14b..29aebf1983 100644 --- a/tests/behat/features/insert-anchor-link.feature +++ b/tests/behat/features/insert-anchor-link.feature @@ -5,7 +5,7 @@ I want to insert a link into my content So that I can link to a external website or a page on my site Background: - Given I add an extension "SilverStripe\CMS\Tests\Behaviour\AdditionalAnchorPageExtension" to the "Page" class + Given I add an extension "SilverStripe\CMS\Tests\Behaviour\AdditionalAnchorPageExtension" to the "Page" class without dev-build And a "page" "Home" And a "page" "About Us" has the "Content" "

My awesome content

" And a "page" "Details" has the "Content" "

My sub-par content

" diff --git a/tests/php/Controllers/LeftAndMainPageIconsExtensionTest/ModuleIconExtension.php b/tests/php/Controllers/LeftAndMainPageIconsExtensionTest/ModuleIconExtension.php index 148c4975ec..f5a01c8db0 100644 --- a/tests/php/Controllers/LeftAndMainPageIconsExtensionTest/ModuleIconExtension.php +++ b/tests/php/Controllers/LeftAndMainPageIconsExtensionTest/ModuleIconExtension.php @@ -2,11 +2,11 @@ namespace SilverStripe\CMS\Tests\Controllers\LeftAndMainpageIconsExtensionTest; -use SilverStripe\CMS\Model\SiteTreeExtension; use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Dev\TestOnly; +use SilverStripe\Core\Extension; -class ModuleIconExtension extends SiteTreeExtension implements TestOnly +class ModuleIconExtension extends Extension implements TestOnly { public static function get_extra_config() { diff --git a/tests/php/Model/SiteTreeBacklinksTest_DOD.php b/tests/php/Model/SiteTreeBacklinksTest_DOD.php index 8f2e86fb36..2888ee2981 100644 --- a/tests/php/Model/SiteTreeBacklinksTest_DOD.php +++ b/tests/php/Model/SiteTreeBacklinksTest_DOD.php @@ -5,9 +5,9 @@ use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HTMLEditor\HTMLEditorField; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; -class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly +class SiteTreeBacklinksTest_DOD extends Extension implements TestOnly { private static $db = [ 'ExtraContent' => 'HTMLText', diff --git a/tests/php/Model/SiteTreeLinkTracking_Extension.php b/tests/php/Model/SiteTreeLinkTracking_Extension.php index b05913d2b4..3ce05100f2 100644 --- a/tests/php/Model/SiteTreeLinkTracking_Extension.php +++ b/tests/php/Model/SiteTreeLinkTracking_Extension.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; -class SiteTreeLinkTracking_Extension extends DataExtension implements TestOnly +class SiteTreeLinkTracking_Extension extends Extension implements TestOnly { protected function updateAnchorsOnPage(&$anchors) { diff --git a/tests/php/Model/SiteTreeTest_AdminDeniedExtension.php b/tests/php/Model/SiteTreeTest_AdminDeniedExtension.php index b73f19a251..a3a3f65c0f 100644 --- a/tests/php/Model/SiteTreeTest_AdminDeniedExtension.php +++ b/tests/php/Model/SiteTreeTest_AdminDeniedExtension.php @@ -3,12 +3,12 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; /** * An extension that can even deny actions to admins */ -class SiteTreeTest_AdminDeniedExtension extends DataExtension implements TestOnly +class SiteTreeTest_AdminDeniedExtension extends Extension implements TestOnly { protected function canCreate($member) { diff --git a/tests/php/Model/SiteTreeTest_Extension.php b/tests/php/Model/SiteTreeTest_Extension.php index 5fa0cdd84d..d01463b0cd 100644 --- a/tests/php/Model/SiteTreeTest_Extension.php +++ b/tests/php/Model/SiteTreeTest_Extension.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; -class SiteTreeTest_Extension extends DataExtension implements TestOnly +class SiteTreeTest_Extension extends Extension implements TestOnly { protected function augmentValidURLSegment() { diff --git a/tests/php/Model/SiteTreeTest_ExtensionA.php b/tests/php/Model/SiteTreeTest_ExtensionA.php index 0e9e0baae6..594fc4fabb 100644 --- a/tests/php/Model/SiteTreeTest_ExtensionA.php +++ b/tests/php/Model/SiteTreeTest_ExtensionA.php @@ -2,11 +2,11 @@ namespace SilverStripe\CMS\Tests\Model; -use SilverStripe\CMS\Model\SiteTreeExtension; use SilverStripe\Control\Controller; use SilverStripe\Dev\TestOnly; +use SilverStripe\Core\Extension; -class SiteTreeTest_ExtensionA extends SiteTreeExtension implements TestOnly +class SiteTreeTest_ExtensionA extends Extension implements TestOnly { public static $can_publish = true; diff --git a/tests/php/Model/SiteTreeTest_ExtensionB.php b/tests/php/Model/SiteTreeTest_ExtensionB.php index be93b57195..3b3ecdb82d 100644 --- a/tests/php/Model/SiteTreeTest_ExtensionB.php +++ b/tests/php/Model/SiteTreeTest_ExtensionB.php @@ -2,11 +2,11 @@ namespace SilverStripe\CMS\Tests\Model; -use SilverStripe\CMS\Model\SiteTreeExtension; use SilverStripe\Control\Controller; use SilverStripe\Dev\TestOnly; +use SilverStripe\Core\Extension; -class SiteTreeTest_ExtensionB extends SiteTreeExtension implements TestOnly +class SiteTreeTest_ExtensionB extends Extension implements TestOnly { public static $can_publish = true; diff --git a/tests/php/Model/VirtualPageTest_PageExtension.php b/tests/php/Model/VirtualPageTest_PageExtension.php index 455cd9b9e9..22ed4719c6 100644 --- a/tests/php/Model/VirtualPageTest_PageExtension.php +++ b/tests/php/Model/VirtualPageTest_PageExtension.php @@ -3,9 +3,9 @@ namespace SilverStripe\CMS\Tests\Model; use SilverStripe\Dev\TestOnly; -use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Extension; -class VirtualPageTest_PageExtension extends DataExtension implements TestOnly +class VirtualPageTest_PageExtension extends Extension implements TestOnly { private static $db = [ // These fields are just on an extension to simulate shared properties between Page and VirtualPage.