0

I have a custom module with some simple code:

function theme_extras_form_alter(&$form, &$form_state, $form_id) {
   if ($form['#id'] == 'views-exposed-form-blog-posts-page') {
      $form['field_post_type_tid']['#options']['All'] = t('Refresh');
      $form['field_post_type_tid']['#options']['3'] = t('<i class="icon-twitter"></i>');
   }
}

The first replacement works beautifully, but the second renders as plain text, rather than html. I need to do this for every form element (in fact, refresh will even be replaced with an icon further down the road). What am I missing here to properly output the html?

Threaded
  • 71
  • 1
  • 8
  • 1
    What type of form input is it? i.e. select, radios? – tyler.frankenstein Aug 07 '13 at 01:51
  • Hey Tyler, thanks for the reply. It is currently using select. – Threaded Aug 07 '13 at 07:55
  • 2
    Unfortunately, HTML cannot be placed within select options. Maybe this will shed some light: http://stackoverflow.com/questions/1895476/how-to-style-a-select-dropdown-with-css-only-without-javascript – tyler.frankenstein Aug 07 '13 at 15:33
  • I think what I'm really looking for is a way to change the output so that it can use normal markup, and maybe output as an unordered list of links. – Threaded Aug 07 '13 at 17:51
  • 1
    Then you're probably looking to use hook_form_alter() to change the field to a different form element type. – tyler.frankenstein Aug 08 '13 at 00:56
  • 1
    Hey Tyler. I appreciate the continued help. I decided to try and ape my original method and instead used some jQuery to integrate the html. Thanks again, I really do appreciate the attempt to help! – Threaded Aug 08 '13 at 03:19

1 Answers1

0

I decided to pull this off using jQuery, as achieving the desired affect using a custom module was not pragmatic and may have, in fact, been overkill. Following is the poorly refactored but working code which got me there:

(function($) {

$(document).ready(function(){

    var link = '<a href="http://project.local/blog-posts?field_blog_post_type_tid=',
        id   = '#edit-field-blog-post-type-tid-';

    $(id + 'all').html(link + 'All"><span class="icon-container"><i class="icon-undo"></i></span></a>');
    $(id + '3').html(link + '3"><span class="icon-container"><i class="icon-music"></i></span></a>');
    $(id + '2').html(link + '2"><span class="icon-container"><i class="icon-camera"></i></span></a>');
    $(id + '5').html(link + '4"><span class="icon-container"><i class="icon-quote-right"></i></span></a>');
    $(id + '1').html(link + '1"><span class="icon-container"><i class="icon-file-text-alt"></i></span></a>');
    $(id + '4').html(link + '4"><span class="icon-container"><i class="icon-film"></i></span></a>');
});

})(jQuery);
Threaded
  • 71
  • 1
  • 8