-
Notifications
You must be signed in to change notification settings - Fork 2
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
Initial review of AnyField #115
Comments
How to access this?Anyfield grew from the linkfield codebase and seems like it has two different goals:
Accessing anyfield as a way to manage any DataObject in a modalBeing able to edit any dataobject relation in a modal is very ambitious because to do it properly you need to get all of the existing dataobject edit form functionality to work into a modal. After a quick look at anyfield I don't think it's close to fulfilling this as I noticed plenty of shortcomings. Just a few were:
It would probably make more sense to transplant some of this code to silverstripe/admin and we'd be doing this in the context of a totally different epic, not one that looks at formally supporting linkfield. If we were to start seriously looking at editing DataObject in modals then I'd want it to be more than just "editing relations on dataobjects" and I'd want it to be the more generic "editing dataobjects". As anyfield grew from linkfield, it can only do relations on dataobjects as it communicates data updates with the server by taking the contents on edit form in the modal, turning it into JSON and sending it to the server via the parent Page edit forms POST request. If we were to start seriously looking at 'editing dataobjects in modals' I think at that point we'd be making a transition to making the CMS fully API driven rather than the existing method of POST form submissions and PJAX responses. That is obviously way too much scope for what we're doing right now which is a linkfield specific epic. Accessing anyfield as a better linkfieldThe other way to view this is that anyfield is just a better implementation of linkfield with no ambitions beyond that. This is how I'll proceed. I won't call out some things that were already called out in the linkfield review e.g. need to write dev docs Main improvements over linkfieldhas_many relations
Security
Test coverage
ArchitecturalOver abstraction
maxime-rainville/silverstripe-react
GraphQL
Documentation
CodePHP
Javascript
Other
Where to from here?
ACs that were intentionally skipped
|
As the ReadMe mentions "AnyField and ManyAnyField are best suited to managing simple DataObjects that are tightly coupled to their owner. This module will not work well for DataObjects with complex relations." I see it more as something similar to the old hasonefield project in purpose. Probably, AnyField should throw an exception if you give it a class with has_many relations. Either way, we will have the same problems with LinkField. e.g.: If you decide to stick a GridField in your Link subclass, LinkField will breakdown.
I don't think that's something we should do. My perception of AnyField is something that complements Gridfield by being simpler and less intrusive. I think there could be a place for both.
It doesn't really add anything new in that front. It just takes the existing drop down that allows you to pick a link type. The main innovation is that when rendered in
Just realised I neglected to provide docs on how to enabled Sorting. A dev has to explicitly say what column they want to use to sort the results.
Just added the missing bit of doc.
I spent a lot of time considering and mitigating this possibility. That's what the This a much bigger concern for AnyField than for a plain LinkField. LinkField will understandably only let you create Links. We probably still want to add some explicit logic to preclude the creating of Links of an invalid type.
I'm not sure this is true. A lot of the extra logic in AnyField is there to accommodate new features that we'll want in LinkField like limiting the type of Links a specific field can create. The only bit you could eliminate by deciding to only support Links are contains in Once you get ride of the Link Type Registry and start looking at scenario this "LinkField should only accept an EmailLink". You could make it a bit more simple by forcing dev to explicitly say if they want the LinkField to accept a sub class of link rather than all Links. But you'll still have to account for the scenario where a someone tries to save an ExternalLink in a field that's pointed to a EmailLink relation. I think once you get stuck into it, you'll find that substituting the "this field can manage any DataObject and its subclasses" assumption with "this field can manage Link DataObject and its subclasses" doesn't allow you to reduce complexity all that much, if at all.
Whether we go with LinkField or AnyField, that's going to do the same thing.
The Link Object needs a We'll need to this no matter what to support
When doing the conversation to AnyField, I tweaked the approach for picking the description to make more amenable to customisation by configuration. If the relevant method or config option is missing from the DataObject, AnyField will default to a sensible generic behaviour.
That method can be called when the data is loaded from the Form (SS_List) or when the data is loaded from the front end (JSON strin). I don't see a way around this.
The primary purpose of this class is to make sure we can determine what DataObject class we expect from looking at the relation ... as opposed to needing the developer to explicitly tell the Field. So far it has proven pretty resilient and I tried to throw quite a few variation at it in the unit test. AnyField will hard fail if it can't figure out what the baseClass is. One limitation would be what would happen if you put a LinkField that wasn't directly tied to a parent DataObject CMS Form. I think LinkField and AnyField are likely to fail in that scenario.
Just be 100% clear, I removed those classes with the assumption that AnyField would exist independently from LinkField and that you would need to insall both module if you wanted to manage Links in an AnyField.
Those IDs are needed because when we send the data to the backend to generate the description for a link, we need an ID to link the response back to a specific record. I used he You'll probably need something like that no matter what. You could try to strip it out on Send, but right now the AnyField doesn't really try to know when its data is being send. It just keeps track of it's state. PHP side, AnyField just choose to ignore any ID that's none-numeric and assume they belong to a new DataObject that needs to be created.
That's just the nature of having two The way around this is to create a secondary owner on Link and use this syntax: private static $has_many = [
'LinkLiskA' => Link::class,
'LinkLiskB' => Link::class.'.SecondaryOwner',
]; You'll have the same problem on LinkField if you try to add support for List. Extra improvements that the AnyField has that LinkField doesn't
|
Following our chat with our bespoke teams, we concluded that we prefer to focus on the LinkField part for now. We may revisit this further down the track. |
AnyField has a lot of feature that could complement/supersede LinkField. But we are not sure how to approach the inter play between both module.
Acceptance criteria
The text was updated successfully, but these errors were encountered: