Skip to content

Instantly share code, notes, and snippets.

@heyMP
Created July 9, 2014 02:33
Show Gist options
  • Save heyMP/47f7d1833bc0e1013394 to your computer and use it in GitHub Desktop.
Save heyMP/47f7d1833bc0e1013394 to your computer and use it in GitHub Desktop.
Replace taxonomy term reference options with images in Drupal
/**
* Implements hook_form_FORM_ID_alter() for premium_plus_order_entityform_edit_form().
*
* Replace the options with images from the taxonomy term
*/
function sh_member_signup_form_premium_plus_order_entityform_edit_form_alter(&$form, &$form_state, $form_id) {
foreach ($form as $formitem_name => $formitem) {
if (isset($formitem['#attributes']['class']) && in_array('field-type-taxonomy-term-reference', $formitem['#attributes']['class'])) {
foreach ($formitem['und']['#options'] as $tid => $option) {
$term = taxonomy_term_load($tid);
$image_display = field_view_field('taxonomy_term', $term, 'field_premplus_image', 'default');
$form[$formitem_name]['und']['#options'][$tid] = $option . drupal_render($image_display);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment