Coder Social home page Coder Social logo

Comments (2)

pxlpnk avatar pxlpnk commented on June 18, 2024

Thank you for your input, keep it coming 👯

There is a bit of a discrepancy between what the user interface allows you to do and what the api allows.
Basically the UI tries to prevent you from breaking stuff, the api on the other hand gives you way more and less opinionated access to content types and entries.
In general deleting a field from a content type before it is activated is ok. However the api will not (at the moment) stop you from deleting a field from an activated content type. Once a content type is activated the field should be disabled.

For the request: adding the disable field makes total sense, make destroy behave like disable is the wrong way to go in my opinion and the api should let you know that this is a bad idea.
I will discuss this with the backend team and will add the disable feature to the roadmap for the gem.

Could you maybe share your code?

from contentful-management.rb.

jsdalton avatar jsdalton commented on June 18, 2024

Makes sense. I actually ended up not deleting any fields, because in my use case I'm trying to delete fields on already activated content types. So ultimately, being able to explicitly disable / reenable fields is the feature that works.

First and foremost, actually adding a property that tracks the disabled status of the field is the most helpful step:

        ::Contentful::Management::Field.class_eval do
          # Contentful Management gem doesn't keep disabled, so monkeypatch it here
          # until this gets implemented
          property :disabled, :boolean
        end

Doing that, disabled just becomes one more property to manage. So for example to disable a given field, I'm doing something like this:

          # Where field_id is the ID of the field we're trying to disable
          fields = content_type.fields.map do |field|
            if field.id == field_id
              field.disabled = true
            end
            field
          end
          content_type.update(fields: fields)

from contentful-management.rb.

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.