Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
To reproduce:
- In a content type with a field using formatter_field, add another test field, no matter what the type or other settings are, the only thing required is the cardinality set to unlimited.
- Go to a node of that type and make sure the field using formatter_field has values.
- Then, from the other test field just created, hit "Add another item".
- Save the node.
- Go back and edit the node and check the formatter_field field values.
- If the issue is still present they should have been set to empty, unchecked, etc
This seems to be caused by the ajax callback triggered by clicking on the button from the test field. During this call the function formatter_field_field_widget_form is run, but the field being processed is not our formatter_field field, but the multivalued field whose "Add another item" button triggered the ajax callback. To avoid this we could add an extra check to formatter_field_field_widget_form:
if (!empty($form_state['values']) && isset($form_state['triggering_element']['#field_instance_name']) && $form_state['triggering_element']['#field_instance_name'] == $instance['settings']['field_name']) {
$path = array($field['field_name'], $langcode);
$items = drupal_array_get_nested_value($form_state['values'], $path);
}
and in the element definition:
element['type'] = array(
'#type'=>'select',
'#field_instance_name'=> $instance['settings']['field_name']
::
Thanks jec006.
Comment | File | Size | Author |
---|---|---|---|
#2 | formatter_field-1762202-2.patch | 1.09 KB | arpieb |
#1 | formatter_field-1762202-1.patch | 1.16 KB | fxarte |
Comments
Comment #1
fxarte CreditAttribution: fxarte commentedHere is a patch with those changes.
Comment #2
arpieb CreditAttribution: arpieb commentedThe above patch actually didn't quite work due to the fact that when another AJAX-enabled field triggered a refresh of the field widget, it didn't populate the $form_state['values'] for this field widget. The attached patch addresses this, as well as "beefing up" the conditional check on $form_state['values'] so we can tell if our field is actually defined prior to calling drupal_array_get_nested_value().
Comment #3
zipymonkey CreditAttribution: zipymonkey commentedI haven't used this fields that cardinality other than 1 but I used patch #2 in another patch and it seems to work fine: http://drupal.org/node/1393488#comment-6653006
Comment #4
futurist CreditAttribution: futurist commentedI noticed that this bug not only occurs when a new value gets added but also when a value is removed, i.e. in an image field: a new image is added or an existing one is removed.
The patch by arpieb in #2 fixes this issue for me.
Comment #5
acrollet CreditAttribution: acrollet commentedPatch applies fine and works well. Taking the liberty of upgrading the priority to major, as this breaks the module's functionality for a fairly common (imo) use case.
Comment #6
claudiu.cristeaI tried by adding a textfield with unlimited cardinality. Cannot reproduce the error. Can you give some more specific details?
Comment #7
acrollet CreditAttribution: acrollet commentedclaudiu.cristea: I was experiencing the issue when using an image field and a formatter field together in a field_collection field of unlimited cardinality.
Comment #8
claudiu.cristeaStill cannot reproduce. I added a collection field with unlimited cardinality. Then defined in the collection 1 image field, 1 formatter filed (pointing to image). I added to collection items and saved the node. Then get back to edit form and pressed "Add another item". Added the 3rd image and saved the node. All 3 items of field collection are in place.
So, what?
Comment #8.0
claudiu.cristeaadding thank you notes
Comment #9
cachesclay CreditAttribution: cachesclay commentedPatch #2 fixed an error we were having when adding/removing fields on a Fieldable Panel Pane in IPE. Admins had to save the FPP twice for a Views Field Formatter. Very helpful, thanks!
Comment #10
ron_s CreditAttribution: ron_s commentedPatch #2 and the patch on this thread (https://www.drupal.org/node/1394566) overlap. I believe #1394566 is the right approach, since it is using the
$instance
and not the$field
.Instance is the version of the field attached to the specific bundle, while field is the generic item not bound to any bundle.
Comment #11
Chris Matthews CreditAttribution: Chris Matthews commentedClosing as a duplicate of issue #1394566: The formatter setting doesn't work on node save or on node edit when changing the image that was committed and pushed to 7.x-1.0-beta5.