-
Notifications
You must be signed in to change notification settings - Fork 115
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 Deprecate getDescription method to prevent it overriding db fields #953
API Deprecate getDescription method to prevent it overriding db fields #953
Conversation
@@ -954,7 +956,10 @@ public function getDescription() | |||
*/ | |||
public function getTypeNice() | |||
{ | |||
$description = $this->getDescription(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since getDescription
is still available IMO it should still be called here. Developers will be used to their descriptions being pulled through for the TypeNice
and may rely on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be deprecated, so it shouldn't be used going forward.
If people rely on it, it will work until it's removed in 5.0.
The change here is a duplicate of what's in the method without any functional difference and is included here as agreed in the original PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a duplicate for the method as declared in this base class, but if someone has overridden the getDescription
method in some subclass and are expecting the returned result of their overridden method to be used in TypeNice
then this will represent a breaking change for them.
I don't know how common that is and whether it's a real cause of concern, just something to consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's fair, though when they find that their custom method is not working anymore after upgrading, they will see the deprecation and adjust their code.
What do you think @emteknetnz, should I keep the code change or remove it and leave just the deprecation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps update getDescription()
in this method to simply return '';
Retain $description = $this->getDescription();
in this method, and then add a conditional if ($description === '') ...
then $description = $this->config()->uninherited('description');
etc
That way if any projects have overridden getDescription()
it will continue to be used for TypeNice
so no BC breakage
I'm not sure how annoying the deprecation warning will be. I'm also not sure if it appears on a subclassed element that implements getDescription()
. We do want the method deprecated, though at the same time we don't really want it annoying a developer on their local box with deprecated warning on since elemental 4 is likely to be around for a long time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I got the suggestion.
My counterpoint was that even with that, if custom project code overrides the getDescription
method to return an empty string instead of getting the config value, the suggested way would trump that and the custom code would have to go and override the getTypeNice
method instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the type hint is only in the doc and not defined as the return type by PHP, can we extend it to return null from getDescription and check for null instead? Custom code returned empty string would still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* @deprecated
* @return string|null
*/
public function getDescrption()
{
return null;
}
public function getTypeNice()
{
$description = $this->getDescription(); // allow a subclass to override the old function
if ($description === null) {
$description = $this->config()->uninherited('description');
if ($description) {
$description = _t(__CLASS__ . '.Description', $description);
}
}
$desc = ($description) ? ' <span class="element__note"> — ' . $description . '</span>' : '';
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK right, the use case being the custom code specifically wants a blank description
Yeah I suppose it's fine, if you wanted to be particularly strict (it does save on arguments about semver, and sometimes weird edge cases), perhaps something like
/** @var string */
private $fallbackToConfig = '__fallback_to_config__';
/** @return string */
public function getDescription()
{
reutrn $this->fallbackToConfig;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we need to retain the following two use cases for BC:
- Developers are calling
getDescription()
directly, or are using$Description
in their templates- The output of this needs to not be changed by this PR.
- Developers are overriding
getDescription()
in their subclass and expecting their overridden content to be used.- Their content must be used in all the same situations where it was used before.
Yes developers can update their code the match the changes - but that's no different from just deleting this method outright. The point of deprecating the method is so that developers can make changes when they have capacity to do so - they should be able to update without making code changes, and then make the code changes as a dedicated intentional (and crucially, separate) effort.
@michalkleiner I've added a comment to this - sorry it's gone so long without being touched. Are you still interested in getting this done? If so please make changes so that the use cases I've outlined are respected in a BC way. |
I'll see this week if I can push it forward. If not I'll close this. |
I was going to co-opt the PR and make the requested changes myself but I don't have permission to edit the PR. |
Can a PR be retrospectively adjusted to allow maintainers push? |
I don't know for sure, but I don't think so unfortunately. |
I looked at the PR and tbh I'm lost on what was going on and what is needed to get it over the line, so will just close it for now. If you can open a new one with what's needed @GuySartorelli that would be appreciated. Thanks! |
Replaced by #1196 |
Complimentary PR to #785
Issue
getDescription
method fromBaseElement
#1106