Closed GuySartorelli closed 6 months ago
Generally I'm in favour of this change, I just can see how someone would be calling now-public methods we think should be protected. Even with everything documented in a changelog I just can't foresee how big an issue that might be, but I guess if someone does that and won't know how to move away from that during a CMS5 upgrade then we can possibly say they're doing something wrong anyway — is that enough of an excuse?
Extension hook methods aren't meant to be called directly - if someone's doing that then yeah I think it's okay to say they're doing something wrong and should call $record->extend()
instead.
If this gets done in time for the beta, it can be in CMS5. Otherwise it will have to wait for CMS6.
I just moved this in refinement. Are there other aspect we think should be refactored?
$this->owner
should be private and people should use the getOwner()
instead.DataExtension
provided no value over Extension.Extension
?I've always thought
$this->owner
should be private and people should use thegetOwner()
instead.
Fully agree - though we might want to have an early idea of how many of these sorts of changes we're looking to make.
This is the sort of change that on its own wouldn't be too painful in an upgrade, but with a few others like it you start to want a tool to assist you in finding and replacing things.
I vaguely remember a rent from
@GuySartorelli
aboutDataExtension
provided no value overExtension
.
This issue deals with deprecating DataExtension
What about strongly typing more or all of
Extension
?
Seems like it'd be easy enough, though perhaps low value since Extension
really only has getOwner()
as far as methods that are actively called by developers, and we can't give that a type other than I guess object
which isn't overly helpful.
I don't really agree with changing ->owner - searching for ->owner->
in sink a quick string search found 720 matches. Changing it's pretty trivial, just find and replace in files and lots of pull-requests. However loads and loads of projects will use ->owner, personally I prefer it because it's less typing. I think that's just adding upgrade friction for basically zero benefit.
I made a rough script for finding implementations of extension hooks, it's not 100% though I bashed it out in less than an hour, easy enough to get it to do everything we need to automate most of it - https://github.com/emteknetnz/extension-protector/blob/main/run.php
I've put this into peer review to discuss what should be done with the list of $doNotMakeHookProtected
in the extension-protector script I create for this issue
Options:
$makeHookProtected
It looks like 2 is actually "1, and create cards to consider doing 2 later" which is what I'd opt for.
@emteknetnz The ACs talk about updating docs but there's no docs PR - were no changes necessary?
Also quite a few with CI still failing after merging the framework PR. Will hold off merging any in case there are larger sweeping changes needed.
Just one PR left with failing CI https://github.com/silverstripe/silverstripe-subsites/pull/571
PRs merged. Assigning to Steve to make the new card discussed in https://github.com/silverstripe/silverstripe-framework/issues/10514#issuecomment-2113703521 for the items that weren't straight forward.
Once that card exists, this issue can be closed.
Created a new card https://github.com/silverstripe/silverstripe-framework/issues/11258
Created a new PR for changelog https://github.com/silverstripe/developer-docs/pull/520
PR merged
https://github.com/silverstripe/silverstripe-framework/pull/10457 made it so that extension hook methods can be
protected
and won't be exposed as callable methods on the object being extended. It should now be considered best practice to make hook methodsprotected
- the only methods which should bepublic
are methods that are intended to be called directly on the object being extended.e.g. you wouldn't call
$record->updateCMSFields()
but you might call$record->getCustomField()
. SoupdateCMSFields()
should beprotected
andgetCustomField()
would be public on theExtension
class.Acceptance Criteria
protected
methods for their extension hook methodsprotected
method signaturesFollow up
PRs
DOC PRs