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.
Let's say I add a textfield field to a user entity.
Cardinality = 1;
After that I see on profile form the following markup wrapped around the textfield:
<div id="field-job-add-more-wrapper"><div class="form-item form-type-textfield form-item-field-job-und-0-value">
<label for="edit-field-job-und-0-value">Job </label>
<input type="text" maxlength="255" size="60" value="CEO" name="field_job[und][0][value]" id="edit-field-job-und-0-value" class="text-full form-text">
</div>
</div>
What seems to be odd.. is this part:
the "-add-more-wrapper" is added to the id in field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state).
Why is this function called??? Is this a bug in field_default_form?
if (!isset($get_delta) && field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {
$elements = field_multiple_value_form($field, $instance, $langcode, $items, $form, $form_state);
}
I cant believe this is the correct behaviour...
Comment | File | Size | Author |
---|---|---|---|
#18 | Screen Shot 2021-07-08 at 9.06.24 PM.png | 64.45 KB | pameeela |
#18 | Screen Shot 2021-07-08 at 9.07.12 PM.png | 43.23 KB | pameeela |
#6 | 1389632-06-single-multiple-values.patch | 4.31 KB | netsensei |
#4 | field-wrapper-test-only.patch | 2.58 KB | marcingy |
#4 | field-wrapper.patch | 4.11 KB | marcingy |
Comments
Comment #1
star-szrI was able to reproduce this behaviour with text fields and textarea widgets only. Drupal 7.10.
The user edit (or node edit) form will show the newly created field wrapped with an ID appended with
-add-more-wrapper
.Comment #2
dabblela CreditAttribution: dabblela commentedI also have this issue; it breaks things like #states because the ID's don't match what is expected. Could a fix be as simple as changing
to
?
Comment #3
marcingy CreditAttribution: marcingy commentedJust about done with a patch I think there are actually couple of issues
* Add more wrapper is added even when an element does not have the option to add more
* A wrapper is added when there is nothing to wrap.
Just trying to get tests to pass locally at the moment
Comment #4
marcingy CreditAttribution: marcingy commentedComment #5
marcingy CreditAttribution: marcingy commentedAnd the patches
Comment #6
netsensei CreditAttribution: netsensei commentedOkay. I rerolled the patch so it works with the new WidgetBase class.
There is a problem though.
$get_delta
is always empty for a single value form element. This causes theform()
function to always go for the$this->formMultipleElements()
method on line 139 instead of the$this->formSingleElement()
on line 120.The
$elements
array will be messy if we negate the isset check on line 114 thus borking all tests.Comment #7
netsensei CreditAttribution: netsensei commentedSetting status.
Comment #8
YesCT CreditAttribution: YesCT commentedrelated?
#1884148: field widget disappears when increase cardinality for image to allow multiple values
Comment #9
mgiffordComment #18
pameeela CreditAttribution: pameeela commentedThis works as expected now.
Cardinality = 1:
Cardinality = Unlimited: