diff --git a/src/Extensions/ElementalAreaUsedOnTableExtension.php b/src/Extensions/ElementalAreaUsedOnTableExtension.php index 0fd8ff33..3d828407 100644 --- a/src/Extensions/ElementalAreaUsedOnTableExtension.php +++ b/src/Extensions/ElementalAreaUsedOnTableExtension.php @@ -20,7 +20,7 @@ class ElementalAreaUsedOnTableExtension extends DataExtension * * @var array $excludedClasses */ - public function updateUsageExcludedClasses(array &$excludedClasses) + protected function updateUsageExcludedClasses(array &$excludedClasses) { $excludedClasses[] = ElementalArea::class; } @@ -31,7 +31,7 @@ public function updateUsageExcludedClasses(array &$excludedClasses) * @param bool $excludeDataObject * @param DataObject $dataObject|null */ - public function updateUsageDataObject(?DataObject &$dataObject) + protected function updateUsageDataObject(?DataObject &$dataObject) { if (!($dataObject instanceof BaseElement)) { return; @@ -51,7 +51,7 @@ public function updateUsageDataObject(?DataObject &$dataObject) * @param array $ancestorDataObjects * @param DataObject $dataObject */ - public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject) + protected function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject) { if (!($dataObject instanceof BaseElement)) { return; diff --git a/src/Extensions/ElementalAreasExtension.php b/src/Extensions/ElementalAreasExtension.php index 565e2618..6b55d6a1 100644 --- a/src/Extensions/ElementalAreasExtension.php +++ b/src/Extensions/ElementalAreasExtension.php @@ -175,7 +175,7 @@ public function getElementalRelations() * * @param FieldList */ - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { if (!$this->supportsElemental()) { return; @@ -218,7 +218,7 @@ public function updateCMSFields(FieldList $fields) /** * Make sure there is always an ElementalArea for adding Elements */ - public function onBeforeWrite() + protected function onBeforeWrite() { parent::onBeforeWrite(); diff --git a/src/Extensions/ElementalCMSMainExtension.php b/src/Extensions/ElementalCMSMainExtension.php index 530b8135..c4bdc1f6 100644 --- a/src/Extensions/ElementalCMSMainExtension.php +++ b/src/Extensions/ElementalCMSMainExtension.php @@ -18,7 +18,7 @@ class ElementalCMSMainExtension extends Extension * * @param Form $form */ - public function updateSearchForm(Form $form) + protected function updateSearchForm(Form $form) { /** @var DropdownField $filterField */ $filterField = $form->Fields()->fieldByName('Search__FilterClass'); diff --git a/src/Extensions/ElementalPageExtension.php b/src/Extensions/ElementalPageExtension.php index e775f508..c63fa4dd 100644 --- a/src/Extensions/ElementalPageExtension.php +++ b/src/Extensions/ElementalPageExtension.php @@ -103,7 +103,7 @@ public function getContentFromElementsForCmsSearch(): string /** * @see SiteTree::getAnchorsOnPage() */ - public function updateAnchorsOnPage(array &$anchors): void + protected function updateAnchorsOnPage(array &$anchors): void { if (!($this->owner instanceof SiteTree)) { return; diff --git a/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php b/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php index 1da3c610..975fb75b 100644 --- a/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php +++ b/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php @@ -15,7 +15,7 @@ class GridFieldAddNewMultiClassHandlerExtension extends Extension /** * @param Form $form */ - public function updateItemEditForm(Form $form) + protected function updateItemEditForm(Form $form) { // NOTE: this extension is applied to new item edit form only diff --git a/src/Extensions/GridFieldDetailFormItemRequestExtension.php b/src/Extensions/GridFieldDetailFormItemRequestExtension.php index 2e562f63..b2e8264b 100644 --- a/src/Extensions/GridFieldDetailFormItemRequestExtension.php +++ b/src/Extensions/GridFieldDetailFormItemRequestExtension.php @@ -12,7 +12,7 @@ */ class GridFieldDetailFormItemRequestExtension extends Extension { - public function updateBreadcrumbs($crumbs) + protected function updateBreadcrumbs($crumbs) { $record = $this->owner->getRecord(); diff --git a/src/GraphQL/Resolvers/Resolver.php b/src/GraphQL/Resolvers/Resolver.php index 674609c2..2d1315e7 100644 --- a/src/GraphQL/Resolvers/Resolver.php +++ b/src/GraphQL/Resolvers/Resolver.php @@ -89,8 +89,8 @@ public static function resolveAddElementToArea( // Assign the parent ID directly rather than via HasManyList to prevent multiple writes. // See BaseElement::$has_one for the "Parent" naming. $newElement->ParentID = $elementalArea->ID; - // Ensure that a sort order is assigned - see BaseElement::onBeforeWrite() - $newElement->onBeforeWrite(); + // Ensure that a sort order is assigned + $newElement->ensureSortSet(); if ($afterElementID !== null) { /** @var ReorderElements $reorderer */ diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 033a2888..2cfd197e 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -319,16 +319,18 @@ public function write( return parent::write($showDebug, $forceInsert, $forceWrite, $writeComponents, $skipValidation); } + protected function onBeforeWrite() + { + parent::onBeforeWrite(); + $this->ensureSortSet(); + } + /** * Increment the sort order if one hasn't been already defined. This * ensures that new elements are created at the end of the list by default. - * - * {@inheritDoc} */ - public function onBeforeWrite() + public function ensureSortSet() { - parent::onBeforeWrite(); - // If a Sort has already been set, then we can exit early if ($this->Sort) { return; diff --git a/src/TopPage/DataExtension.php b/src/TopPage/DataExtension.php index a2d0d602..7bb89aa3 100644 --- a/src/TopPage/DataExtension.php +++ b/src/TopPage/DataExtension.php @@ -56,7 +56,7 @@ class DataExtension extends BaseDataExtension * * @throws ValidationException */ - public function onAfterWrite(): void + protected function onAfterWrite(): void { $this->setTopPage(); } @@ -64,7 +64,7 @@ public function onAfterWrite(): void /** * Extension point in @see DataObject::duplicate() */ - public function onBeforeDuplicate(): void + protected function onBeforeDuplicate(): void { $this->clearTopPage(); } @@ -72,7 +72,7 @@ public function onBeforeDuplicate(): void /** * Extension point in @see DataObject::duplicate() */ - public function onAfterDuplicate(): void + protected function onAfterDuplicate(): void { $this->updateTopPage(); } @@ -198,7 +198,7 @@ public function withFixedTopPage(int $topPageID, callable $callback) } } - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->removeByName('TopPageID'); } diff --git a/src/TopPage/FluentExtension.php b/src/TopPage/FluentExtension.php index d81e86ae..fa802875 100644 --- a/src/TopPage/FluentExtension.php +++ b/src/TopPage/FluentExtension.php @@ -29,7 +29,7 @@ class FluentExtension extends DataExtension 'TopPageLocale' => 'Varchar', ]; - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $fields->removeByName('TopPageID'); $fields->removeByName('TopPageLocale'); diff --git a/src/TopPage/SiteTreeExtension.php b/src/TopPage/SiteTreeExtension.php index 320576d6..b6124fb4 100644 --- a/src/TopPage/SiteTreeExtension.php +++ b/src/TopPage/SiteTreeExtension.php @@ -37,7 +37,7 @@ class SiteTreeExtension extends BaseSiteTreeExtension * * @throws ValidationException */ - public function onAfterWrite(): void + protected function onAfterWrite(): void { $this->setTopPageForElementalArea(); $this->processDuplicationFromOriginal(); @@ -48,7 +48,7 @@ public function onAfterWrite(): void * * @param SiteTree $original */ - public function onBeforeDuplicate(SiteTree $original): void + protected function onBeforeDuplicate(SiteTree $original): void { $this->initDuplication($original); } @@ -60,7 +60,7 @@ public function onBeforeDuplicate(SiteTree $original): void * @param bool $doWrite * @throws ValidationException */ - public function onAfterDuplicate(SiteTree $original, $doWrite): void + protected function onAfterDuplicate(SiteTree $original, $doWrite): void { $this->processDuplication($original, (bool) $doWrite); } diff --git a/tests/Behat/Extension/UniqueHtmlEditorConfigExtension.php b/tests/Behat/Extension/UniqueHtmlEditorConfigExtension.php index 1e6d91a3..ad858fa2 100644 --- a/tests/Behat/Extension/UniqueHtmlEditorConfigExtension.php +++ b/tests/Behat/Extension/UniqueHtmlEditorConfigExtension.php @@ -14,7 +14,7 @@ */ class UniqueHtmlEditorConfigExtension extends Extension implements TestOnly { - public function updateCMSFields(FieldList $fields) + protected function updateCMSFields(FieldList $fields) { $wysiwyg = $fields->dataFieldByName('HTML'); if ($wysiwyg instanceof HTMLEditorField) { diff --git a/tests/Extensions/ElementalCMSMainExtensionTest.php b/tests/Extensions/ElementalCMSMainExtensionTest.php index 464007d3..f5a022c2 100644 --- a/tests/Extensions/ElementalCMSMainExtensionTest.php +++ b/tests/Extensions/ElementalCMSMainExtensionTest.php @@ -7,6 +7,7 @@ use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; +use \ReflectionMethod; class ElementalCMSMainExtensionTest extends SapphireTest { @@ -19,7 +20,10 @@ public function testRemovesDefaultEmptyStringFromClassFilter() $fields = new FieldList($field); $form = new Form(null, null, $fields, new FieldList()); - $extension->updateSearchForm($form); + // Call extension method ElementalCMSMainExtension::updateSearchForm($form) which is protected + $method = new ReflectionMethod(ElementalCMSMainExtension::class, 'updateSearchForm'); + $method->setAccessible(true); + $method->invoke($extension, $form); $this->assertEmpty($field->getEmptyString(), 'Empty string should be empty'); $this->assertFalse($field->getHasEmptyDefault(), 'Empty string should not have an empty default'); diff --git a/tests/Src/TestContentForSearchIndexExtension.php b/tests/Src/TestContentForSearchIndexExtension.php index f1ba7e75..988eb612 100644 --- a/tests/Src/TestContentForSearchIndexExtension.php +++ b/tests/Src/TestContentForSearchIndexExtension.php @@ -7,7 +7,7 @@ class TestContentForSearchIndexExtension extends Extension implements TestOnly { - public function updateContentForSearchIndex(&$content) + protected function updateContentForSearchIndex(&$content) { $content = 'This is the updated content.'; } diff --git a/tests/Src/TestElementContentExtension.php b/tests/Src/TestElementContentExtension.php index d73931b3..78bb12d7 100644 --- a/tests/Src/TestElementContentExtension.php +++ b/tests/Src/TestElementContentExtension.php @@ -13,7 +13,7 @@ class TestElementContentExtension extends DataExtension implements TestOnly 'MyEnum' => 'Enum("Sunny, Cloudy", "Sunny")' ]; - public function updateContentForCmsSearch(array &$contents) + protected function updateContentForCmsSearch(array &$contents) { $contents[] = 'This content is from an extension hook'; }