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.
When printing multi-valued fields in notification emails, only the first value gets printed.
I've traced this back to the token replacement of the [entityform:entityform-submitted-data]
token, used in the email variable. Lines 198-206 of the entityform_tokens()
function in entityform.module
are the problem, I believe:
if (!empty($items)) {
$autofields[$field_display['weight']] = array(
'field_name' => $instance['field_name'],
'options' => array('type' => $field_display['type'], 'settings' => $field_display['settings']),
);
$autofields[$field_display['weight']] = field_view_value('entityform', $entityform, $instance['field_name'], $items[0], $field_display);
$autofields[$field_display['weight']]['#title'] = $instance['label'];
}
This line, gets only the first field value ($items[0]
):
$autofields[$field_display['weight']] = field_view_value('entityform', $entityform, $instance['field_name'], $items[0], $field_display);
I propose replacing lines 198-206 with the following, which adds the render array for each field value to the $autofields
array:
if (!empty($items)) {
$field = array();
foreach($items as $count=>$item) {
$field[$count] = field_view_value('entityform', $entityform, $instance['field_name'], $items[$count], $field_display);
}
$autofields[$field_display['weight']] = $field;
$autofields[$field_display['weight']]['#title'] = $instance['label'];
}
Comment | File | Size | Author |
---|---|---|---|
#10 | 1969014-multivalue-10.diff | 1.15 KB | impleri |
#6 | multivalue.diff | 785 bytes | impleri |
Comments
Comment #1
bjcooper CreditAttribution: bjcooper commentedMaking this change may also require you to update
entityform-submittd-data.tpl.php
so that multi-value fields don't have all their values rendered one-after-the-other on one line.I'd suggest changing line 28:
To something like this:
Comment #2
tedbowI haven't had time to look at this yet but for 2.x I am thinking of removing the token functionality from Entityform an putting it into this module - http://drupal.org/sandbox/tedbow/1674042
The idea is that is more generalized functionality that should work for any fieldable entity. It provides a token for the text output of every entity type and every view mode.
It has been awhile since I wrote the code. So it might be updated with the logic from this module.
Right now Entity to Text actually tries to convert an renderable array of the Entity output text.
The way the token works in Entityform is that it gets the field values and outputs them directly.
The Entity to Text module would only be required for Entityform Notifications.
Can you check to see if the tokens provided by that module work for you?
Comment #3
tedbowI haven't had time to look at this yet but for 2.x I am thinking of removing the token functionality from Entityform an putting it into this module - http://drupal.org/sandbox/tedbow/1674042
The idea is that is more generalized functionality that should work for any fieldable entity. It provides a token for the text output of every entity type and every view mode.
It has been awhile since I wrote the code. So it might be updated with the logic from this module.
Right now Entity to Text actually tries to convert an renderable array of the Entity output text.
The way the token works in Entityform is that it gets the field values and outputs them directly.
The Entity to Text module would only be required for Entityform Notifications.
Can you check to see if the tokens provided by that module work for you?
Comment #4
LulzCannon CreditAttribution: LulzCannon commented@bjcooper
Hello, I'm working with tedbow and it would help if you submit a patch file
Thank You For Your Understanding
Comment #5
LulzCannon CreditAttribution: LulzCannon commentedI have confirmed the problem
Comment #6
impleri CreditAttribution: impleri commentedWhy not just used field_view_field() instead of field_view_value()?
Comment #7
gmclelland CreditAttribution: gmclelland commented@impleri - I manually applied the code in your patch since it was so small. It did work for my case, the multivalue form values came through in the email. The only problem is that the formatting was messed up. It printed the field labels twice in the email for each field.
Here is an example of what was printed in the email:
Any suggestions on how to prevent this?
Comment #8
gmclelland CreditAttribution: gmclelland commentedFor anyone who wants a quick fix on the 1.x-branch.
Download https://drupal.org/project/entity2text
Go to /admin/config/system/variable/module
Edit the correct Email variable - in my case "Email Entityform Admin"
Change the body of the email to use [entityform:textexport-email] instead of [entityform:entityform-submittd-data]
Hope that helps
Comment #9
tedbowThanks for mentioning entity2text. that is my project that takes the logic out of Entityform. I think that is the better way to go.
Comment #10
impleri CreditAttribution: impleri commentedIt's coming out twice because entityform-submittd-data.tpl.php explicitly renders the title as an h2 tag before rendering the entire field. I'm not entirely sure how to render the title separately without doing something horribly bad (i.e. hardcoding the HTML for #title in entityform.module or removing $field['#title'] before render($field) in entityform-submittd-data.tpl.php). I'd think changing the template would be preferable to hardcoding in the module file. I've added to the #6 an unset in the template.
Comment #10.0
impleri CreditAttribution: impleri commentedChanging back-ticks to code tags.
Comment #11
tedbow@impleri or whoever might find this.
You can override entityform-submittd-data.tpl.php in your theme or use preprocess functions
Comment #12
mibfire CreditAttribution: mibfire commented@impleri This way the ":" wont be removed after the title.