我有一个带有一些简单代码的自定义模块:
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>');
}
}
第一个替换工作很漂亮,但第二个替换为纯文本,而不是HTML。我需要为每个表单元素执行此操作(实际上,刷新甚至会被更远的图标替换)。我在这里错过了什么来正确输出html?
答案 0 :(得分:0)
我决定使用jQuery来解决这个问题,因为使用自定义模块实现所需的效果并非实用,事实上可能有点过分。以下是重构不佳但工作的代码让我在那里:
(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);