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 using fivestar fields in embedded view, the rendered select elemens are assigned the same ids. Only the first instance of embedded view saves votes correctly.
To prevent this you may implement the following hooks:
function mymodule_element_info_alter(&$type){
$type['fivestar']['#process'][] = 'mymodule_process_fivestar';
}
function mymodule_process_fivestar(&$element){
$element['vote']['#ajax']['callback'] = 'mymodule_fivestar_ajax_submit_hook';
$element['vote']['#parents'][0].=$element['#settings']['content_id'];
return $element;
}
function mymodule_fivestar_ajax_submit_hook(&$form, &$form_state) {
$content_id = $form['vote']['#settings']['content_id'];
$form_state['values']['vote'] = $form_state['values']['vote'.$content_id];
return fivestar_ajax_submit(&$form, &$form_state);
}
Comment | File | Size | Author |
---|---|---|---|
#1 | 0001-allow-multiple-fivestar-fields-in-embedded-views.patch | 1.44 KB | drone.ah |
Comments
Comment #1
drone.ah CreditAttribution: drone.ah commentedA patch to the module based on the code above.
Comment #3
dbt102 CreditAttribution: dbt102 commentedPlease test with 7.x-2.2 release and report back, as there have been a lot of fixes applied since then.