I'm using field_group with field_collection. I'm *pretty sure* the problem is on field_group, but not 100% sure.
This is a product feedback tool.
I need a way to pre-load up 5 different products so I used this: https://drupal.org/comment/8462791#comment-8462791
It works great.
Let's assume this:
function custom_form_feedback_node_form_alter(&$form, &$form_state, $form_id) {
$items_count = 6;
$field_name = 'field_fieldcollection';
$form_theme = $form[$field_name][LANGUAGE_NONE]['#theme'];
// Remove delete and add more buttons
$form[$field_name][LANGUAGE_NONE][0]['remove_button']['#access'] = FALSE;
$form[$field_name][LANGUAGE_NONE]['add_more']['#access'] = FALSE;
$items = &$form_state['field'][$field_name][LANGUAGE_NONE];
// Generate required number of fields collection
if ($items_count > 1 and $items['items_count'] != $items_count) {
$items['items_count'] = $items_count;
$items['field']['cardinality'] = $items_count;
$form[$field_name][LANGUAGE_NONE] = field_multiple_value_form($items['field'], $items['instance'], LANGUAGE_NONE, array(), $form, $form_state);
// Reset theme function, as field_multiple_value_form hijacks it
$form[$field_name][LANGUAGE_NONE]['#theme'] = $form_theme;
}
echo 'Going in';
// Fill generated fields with data
for ($delta = 0; $delta < $items_count; $delta++) {
$form['field_fieldcollection'][LANGUAGE_NONE][$delta]['#groups']['group_feedback_name']->label = "Feedback for ".$delta;
}
}
Here is the line where the label should be set:
$form['field_fieldcollection'][LANGUAGE_NONE][$delta]['#groups']['group_feedback_name']->label = "Feedback for ".$delta;
The problem: The label always ends up as "Feedback for 5". (5 is the last item that gets looped through since count starts at 0)
Here is the array that it's modifying
[#groups] => Array
(
[group_feedback_name] => stdClass Object
(
[id] => 5
[identifier] => group_feedback_name|field_collection_item|field_feedback|form
[group_name] => group_feedback_name
[entity_type] => field_collection_item
[bundle] => field_feedback
[mode] => form
[parent_name] =>
[table] => field_group
[type] => Normal
[export_type] => 1
[disabled] =>
[label] => Feedback for Full team 5 member delta4
[weight] => 0
[children] => Array
(
[0] => field_feedback_fielda
[1] => field_feedback_fieldb
)
[format_type] => fieldset
[format_settings] => Array
(
[formatter] => collapsible
[instance_settings] => Array
(
[description] =>
[classes] =>
[required_fields] => 1
)
)
)
)
What I've done:
1. I've tried changing the id and weight, no luck.
2. I put an echo $delta in the loop and it DOES iterate properly: 0, 1, 2, 3, 4, 5. So I know it's working (I also change other fields in the code and it works fine)
3. I noticed that when I changed the field group from a div to html in manage fields, it changes title properly! Very strange.
4. I tried setting weights on my module/node_group - no go.
I'm thinking something is overriding the label but I cannot figure this out and I've spent hours on it.
Comments
Comment #1
thefoo CreditAttribution: thefoo commentedComment #2
thefoo CreditAttribution: thefoo commentedFixed it. The problem was with the object for the label. I had to set a pre_render on the field collection in hook_field_attach_form() and then I was able to change the label in the pre_render function.
Comment #3
thefoo CreditAttribution: thefoo commented