-
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
Form schema fixes #5239
Form schema fixes #5239
Conversation
Also moved keys of higher importance to start of array, easier to review this way
Temporary measure until we implement nested fields
More of a standard API approach to return data by default, and make customisation via HTTP headers an optional mode.
The RFC requires a FormField implementation to override $schemaDataType, but its defined on the trait - which can't be redefined by a field subclass. In the end, the trait was never designed to be reuseable on classes other than FormField. We need to admit that architecturally, we'll have to add all that API weight to the base FormField class because of the way forms are structured in SilverStripe (mainly due to a missing layer of indirection in getCMSFields implementations). Also implemented the $schemaDataType on fields where its known. See silverstripe#4938 See http://php.net/manual/en/language.oop5.traits.php#language.oop5.traits.properties.example
@silverstripe/core-team We're hoping to get this pull request over the line in the next 48h because we have an opportunity for staff to fix things during an internal hackday here at SilverStripe Ltd on NZ Friday, ideally without too much branching fragmentation. Can you please review in your respective areas of expertise (PHP and/or JS/React)? @flashbackzoo, @scott1702 and myself have largely peer-reviewed each others work here, but would be good to get the thumbs up from at least one other core committer since these pull requests lay the ground work for further React integration. You'll see some |
* | ||
* @var string | ||
*/ | ||
protected $schemaDataType; |
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.
Would there be any merit in storing these somewhere, perhaps as constants? I can foresee myself getting the case wrong
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.
+1 for class constants on the trait object, with the values set to these strings?
FormFieldSchemaTrait::TYPE_STRING = 'String';
FormFieldSchemaTrait::TYPE_HIDDEN = 'Hidden';
It'll also make changes that create a new one of these data types will have a commit back here with a new constant, which seems an appropriate level of announcement.
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.
Can we add a docblock note saying that the value for this should be set in definition of the FormField subclasses. I'm not sure if that blocks us from using class constants for the values, though.
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.
+1 for constants for types. They should be reasonably fixed, unless the universe invents new primitive data types. :D
Gah, it sucks that we have to lose the trait. Is it just the one public function getSchemaDataType() {
if (!$this->schemaDataType) {
$this->schemaDataType = 'Text';
}
return parent::getSchemeDataType();
} Or possibly call |
@kinglozzer @tractorcow Where do you see the advantage in the trait? For me, it's on the same level as creating a "section" in a class definition through some kind of PHP comment markers. I can't see a reuse for this trait outside of the |
* @package forms | ||
* @subpackage core | ||
*/ | ||
class FormField extends RequestHandler { | ||
|
||
use SilverStripe\Forms\Schema\FormFieldSchemaTrait; |
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, so this comment is about this entire commit but I have to say that this is quite surprising. I don't see the fact that the trait is used in 1 place as a reason not to break the code into smaller pieces.
Perhaps the trait should mark abstract function getSchemaDataType()
, and the implementation of only that method is pulled into FormField
?
I'm with @kinglozzer on this one. I think breaking down code into smaller pieces is a pretty fundamental piece of good software design. I'd shift only the implementation of |
OK three votes for traits (@sminnee, @kinglozzer, @tractorcow , one against (@chillu - in this context). I'll add the trait back in, and move |
Jumping in for no good reason, while I agree that breaking code into smaller pieces is good design, using a trait to do it seems a bit smelly. You can't inject or replace traits, and they share the same access space as the class they're attached to. Why isn't this a seperate class with a decorator pattern? If the argument is "Form Fields should be able to override specific behaviour", the argument for moving that out into a different class is the same as the argument for moving the base trait behaviour into a seperate class. |
I like traits but I don't care that strongly about it in this case. I'd have done it if it were up to me, but happy for it to be left out for this PR.
Also fine with me. |
I'm going to merge, since "moving schema into a trait, extension, or other class" isn't something that we can't do at a later date. The tests pass so let's keep moving onwards. |
Maybe I'll wait for @chillu to respond to the query on using constants; Since that seems to be the only un-addressed point here. See #5239 (comment) |
OK well, if Ingo and Damian are both okay with the solution, I'm not going to block merge of this. |
However, it would be good to hear if @kinglozzer thinks we should hold fire and refactor this some more before merging... |
Yeah moving it back into a trait is my preference, but I don’t feel strongly enough about it to block merge, so +1. Same for the constants I guess - there’s no reason we can’t merge this and address them in a subsequent PR |
9a424e3
to
55f1293
Compare
OK, updated the PR according to feedback:
|
Further work on #4938, in preparation for a React-powered asset and campaign admin.
/cc @tractorcow @flashbackzoo