Comments (7)
comment by: @sminnee (sminnee)
created at: 2012-04-18
I'd say it should throw an InvalidArgumentException
. Easily caught.
from silverstripe-framework.
I just came on to make nearly the same proposal but found this one. I think if the $insertBefore argument is invalid, the field should be inserted at the start rather than the end of the FieldList.
from silverstripe-framework.
In the alternative, an exception should be thrown to indicate that the "existing field" could not be found.
I think so.
I just came on to make nearly the same proposal but found this one. I think if the $insertBefore argument is invalid, the field should be inserted at the start rather than the end of the FieldList.
This runs the risk of issues that would otherwise be emitted to the user to be silently hidden, and never fixed.
from silverstripe-framework.
I think the proposal to always add the field is more practical. I expect this method to act just like 'insert' but with the added convenience of being able to specify a preferred position. Developers don't always know for a sure that the field they're referencing will exist, but as OP said, they will usually want to add the field anyway. A module author might expect a core field to be available for instance, but it might have been removed by user code. Or a field may be available on most pages, but hidden on a few page types. Throwing an error would break the app and might be quite tricky to fix, whereas inserting a field in an unexpected position isn't likely to have a big impact. Forcing developers to check for the existence of a field before calling insertBefore seems like overhead that could be avoided.
Maybe we could meet half way and add a third argument like $strict
, to determine what should happen if the field can't be found. If $strict=false
add the field to the fieldlist anyway. If $strict=true
throw an exception. Default to false? :)
from silverstripe-framework.
I agree with @jonom that it should just work and that an exception is a bit much for adding fields to the CMS.
from silverstripe-framework.
The current implementation of this is that insertBefore() returns false when it fails to insert, and that it also traverses CompositeFields when attempting to insert.
So, I think the fix for this is to add a $appendIfMissing = true
flag to the method signature, and set that to false for the CompositeField traversla.
from silverstripe-framework.
Fixed with #8427 in the SS 4.3.x release line
from silverstripe-framework.
Related Issues (20)
- [Bug] TinyMCEConfig breaks when using option `extended_valid_elements` on a custom Config. HOT 25
- Correctly check if values from `ini_get()` are true-like or not HOT 1
- Cache is not correctly shared between CLI and non-CLI HOT 2
- Create new `Environment::getAsBoolean()` method HOT 9
- Add support for paratest HOT 2
- proper return types HOT 4
- Trailing slash also added to external redirects HOT 7
- MoneyField: Move field generation from constructor to custom method HOT 1
- mariadb builds broken HOT 2
- encryptWithUserSettings assumes there is a salt HOT 1
- Form scaffolder should keep original field order HOT 2
- NumericField doesn't valid properly numbers > 1000 with locale fr-Fr HOT 3
- type mismatch HOT 1
- Orphan polymorphic relations get assigned to random DataObject class HOT 3
- Run CanonicalURLMiddleware in dev / test. HOT 2
- Add Nice() to DBField HOT 10
- BUG Eager loading with multiple objects pointing to the same has_one trigger extra db fetch HOT 1
- TimeField should deal better with partial times HOT 1
- Improve phpdoc types HOT 2
- GridField breadcrumbs may use incorrect casting for titles
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from silverstripe-framework.