Skip to content
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 FormField API #11464

Merged

Conversation

emteknetnz
Copy link
Member

Issue #11422

@emteknetnz emteknetnz marked this pull request as ready for review November 12, 2024 22:05
@@ -101,6 +101,7 @@ class DateField extends TextField
* to detect invalid values.
*
* @var mixed
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
* @deprecated 5.4.0 Use $value instead

Presumably if people want to get the value, they should use the value property. Or the getValue() method.
Please apply this to the other rawValue deprecation phpdocs as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's correct as is as $this->value is still getting modified in CMS 5 - as mentioned on #11449 (comment) this property has a specific purpose

Copy link
Member

@GuySartorelli GuySartorelli Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment mentions the past tense, and #11449 (comment) says that getValue() should return the value "as unmodified as possible". Which I took to mean that the value property would now be the raw value, and the various methods for getting the value are where any modification of the value would take place.

Is there no way to get just the value that was set to the field now? I thought that was explicitly the purpose of getValue()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of Date/Datetime/TimeField, $this->value will get modified after calling setValue($value). $this->rawValue is explicitly not getting modified at any point. There's no equivalent functionality in CMS 5.

My intention, at least, in CMS 6 at least is to not modify $this->value after setting it so that when validation is run it's running on the value that was set by the developer, though in practice Fields could still alter $this->value.

tl;dr Will be removed without equivalent functionality to replace it :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in person - $value is functionally equivalent to $rawValue even if the exact value isn't identical

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

*/
protected function extendValidationResult(bool $result, Validator $validator): bool
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced by the `updateValidate` extension hook');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method doesn't get replaced with the extension hook - if I'm calling this method in my custom form field I don't now need to implement an extension class, I need to call extend() directly.

Suggested change
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced by the `updateValidate` extension hook');
Deprecation::noticeWithNoReplacment('5.4.0', 'Use extend("updateValidate") instead');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the phpdoc and the changelog

Copy link
Member Author

@emteknetnz emteknetnz Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updateValidate hook does not exist in CMS 5, so we cannot give this recommendation.

Copy link
Member

@GuySartorelli GuySartorelli Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use extend() directly instead then. The fact is that you can stop calling this method in 5 immediately - its replacement is the extend() method. The change of extension hook method isn't really related to this method being deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how you'd use extend() directly in CMS 5, or at least why you would

The thing being replaced here has a bool + a Validator for params. The functionality that's replacing it in CMS 6 has a ValidationResult param instead.

Presumably you'd need to implement something sort of convoluted in CMS 5 for this to work ... only to then replace it straight away in CMS 6?

Copy link
Member

@GuySartorelli GuySartorelli Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how you'd use extend() directly in CMS 5, or at least why you would

extendValidationResult() is ultimately an abstraction around $this->extend('updateValidationResult', $result, $validator);

You can just call that directly.

In CMS 5 you'll get a deprecation warning if you're calling extendValidationResult(). One way to silence that is to call extend() directly instead of calling extendValidationResult().

In CMS 6 that will also be the solution - calling extend(), since extendValidationResult() will no longer exist. Just you'll be passing a different hook name and different args, which is not usually information we include in deprecation notice messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@GuySartorelli GuySartorelli merged commit d74670b into silverstripe:5 Nov 14, 2024
14 checks passed
@GuySartorelli GuySartorelli deleted the pulls/5/formfield-depr branch November 14, 2024 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants