Giter Site home page Giter Site logo

Comments (7)

silverstripe-issues avatar silverstripe-issues commented on July 16, 2024

comment by: @sminnee (sminnee)
created at: 2012-04-18


I'd say it should throw an InvalidArgumentException. Easily caught.

from silverstripe-framework.

jonom avatar jonom commented on July 16, 2024

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.

tractorcow avatar tractorcow commented on July 16, 2024

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.

jonom avatar jonom commented on July 16, 2024

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.

dhensby avatar dhensby commented on July 16, 2024

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.

sminnee avatar sminnee commented on July 16, 2024

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.

robbieaverill avatar robbieaverill commented on July 16, 2024

Fixed with #8427 in the SS 4.3.x release line

from silverstripe-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.