-
Notifications
You must be signed in to change notification settings - Fork 32
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
Updating editor interface for single field resets editor interfaces and help text for other fields #155
Comments
Hey @a-lehdet, Sorry that happened, but this because the CMA API only allows PUT requests and not PATCH requests, so you need to specify the whole payload in order to update it without losing information. What I recommend you to do is to update it by doing something like: client = Contentful::Management::Client.new(<TOKEN>)
space = client.spaces.find(<SPACE-ID>)
editor_interface = client.editor_interfaces(space_id, environment_id, content_type_id).default
control = editor_interface.controls.detect { |c| c['fieldId'] == 'fieldName' }
control['settings'].update('helpText' => 'some help text') unless control.nil?
editor_interface.save This will avoid losing data by removing existing configuration from the editor interface. Hope this helps, Cheers |
Thanks for the response and help @dlitvakb, Now that you have explained it, it makes total sense given the structure of the payload. However, as this is a bit of "you just need to know it" issue, it might be worthwhile explaining this in the documentation more in-depth as it was not particularly intuitive nor obvious...not to me, at least. 😄 |
Hi @dlitvakb, As the example you provided no longer works with the current version, I could really use some help as the documentation is still scarce regarding editor interfaces and help texts. Basically what I'm trying to archive is loop through all the fields of a content type and set If you could provide a code example how this can be done, I would appreciate it very much. :) |
Could you explain further what's not working? As there's no new breaking published version since that comment has been made. Cheers |
@dlitvakb I'm getting the following error.
In addition, I'm a bit puzzled that the example connects to space rather than environment. I noticed that editor interfaces of a particular content type can be accessed like this...
...but I wasn't able to figure out how to set values for |
Can you provide me the snippet that throws that error? Cheers |
Here's the code. The purpose of the
|
So far what I've got this, basically just shooting in the dark...
Trying to save using |
Hey @a-lehdet, I'll dig deeper into this as the snippet above (which I now updated to support environments) should work and will provide you an answer by around tomorrow this time. Cheers |
Hey @a-lehdet, This is indeed something that's currently wrong in the SDK, though it's not because it's a bug, it's just because it's implemented a bit differently. I'm going to add a I will create a PR and get it reviewed as soon as possible, Cheers |
Hi @dlitvakb, Thanks for investigating the issue. At the moment I've decided to proceed with the approach described in the first message of this thread (i.e. set the widgets and help texts in a single hash), but latter approach would definitely be more elegant, so adding the |
This is the snippet with how the updated SDK works: require 'contentful/management'
client = Contentful::Management::Client.new(ENV['CF_TEST_CMA_TOKEN'])
space = client.spaces.find('facgnwwgj5fe')
environment = space.environments.find('master')
content_type = environment.content_types.find('cat')
editor_interface = content_type.editor_interface.default
control = editor_interface.controls.detect { |c| c['fieldId'] == 'name' }
if control['settings'].nil?
control['settings'] = {'helpText' => 'some help text'}
else
control['settings'].update('helpText' => 'some help text')
end
editor_interface.save Creating the PR right now, Cheers |
This has just been released as version 2.2.0 Cheers |
Hi,
I used the following code to change the editor interface of a single field in a content type. It appears that in the process some of the editor interfaces settings of other fields in the same content type have been changed/reset and the help texts have vanished.
The text was updated successfully, but these errors were encountered: