-
Notifications
You must be signed in to change notification settings - Fork 824
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
Add Nice() to DBField #11169
Comments
What would the method return by default? |
I would go with a non nullable string, since the goal is often to use it for display purpose DBBoolean : yes/no This way, you can be sure you get a string value out of any DBField object |
That makes sense for the return |
In a minor release it could throw an exception as that would mean it's called on something where the subclass doesn't implement the method. |
oh for the DBField instance? I was going to propose /**
* @return string
*/
public function Nice()
{
return (string) $this->value;
} |
Hmm. I think throwing an exception is effectively the same as just not adding the method in the first place - either way you can't call it on subclasses that don't implement it without an error being thrown. Presumably the main use case for this is in templates or in On the other hand I feel like returning just the raw value isn't really desirable behaviour for I think for CMS 5 it might make sense to just implement it in concrete subclasses of |
Not having the method in the base class is the main issue here: a lot of methods are typed against a DBField and therefore don't know if they can rely on the Nice method being present eg: silverstripe-framework/src/Forms/GridField/GridFieldDataColumns.php Lines 263 to 269 in 5ab9ded
maybe the Nice method should be by default an alias of ->forTemplate since that's already how it's being used anyway. Then in subclasses it can be overridden accordingly. |
Yeah, that'd probably be okay. I can live with that. |
Fixes silverstripe#11169 (cherry picked from commit 2c35b8d)
Gonna keep this open and raise a CMS 6 PR to make the method abstract. |
Actually nevermind, fortemplate is good enough. 😅 |
This work needed to be reverted - see #11191 for details. |
Description
Currently, Nice() is only implemented in subclasses. This means that if you have something like dbObject('MyField')->Nice() phpstan will complain about it.
My proposal is to add as a base method a "Nice" function returning a string (could be a docblock type for now for no bc break, but i'm pretty much sure the use case is to get a string at the end of the day) returning the value or a string if null.
Acceptance Criteria
DBField
class has a newNice()
method, with a strict return type of?string
DBField::Nice()
returns$this->forTemplate()
DBField
which already implements aNice()
method respect the new strict return typeGridFieldDataColumns::castValue()
is updated to remove thenl2br
andraw2xml
function calls (i.e. remove sanitisation) -Nice()
is expected to always be safe to use.Nice()
method they include in their own projects or modules output safe values.GridField
escapes HTML content inappropriately #11191PRs
ENH Add Nice to DBField #11184The text was updated successfully, but these errors were encountered: