Drupal 7 - 在#link表单类型条目中添加HTML? [英] Drupal 7 - add HTML inside #link form type entry?

查看:181
本文介绍了Drupal 7 - 在#link表单类型条目中添加HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向Drupal 7 #type 链接表单元素的 #title 字段添加HTML标记。输出应该如下所示:

I need to add HTML markup to the #title field of a Drupal 7 #type link form element. The output should look roughly like this:

<a href="/saveprogress/nojs/123" id="saveprogress-link" class="ajax-processed">
  <span data-icon="&#61515;" aria-hidden="true" class="mymodule_symbol"></span>
  Save Progress
</a>

由于我正在做一些ajax表单,我不能只使用 #markup l()函数。以下是一个没有跨度的示例:

Since I'm doing some ajax forms, I can't just use #markup and l() function. Here's an example without the span:

function mymodule_save_progress_link($nid) {
  return array(
    '#type' => 'link',
    '#title' => t('Save Progress'),
    '#href' => 'saveprogress/nojs/' . $nid,
    '#id' => 'saveprogress-link',
    '#ajax' => array(
      'wrapper' => 'level-form',
      'method' => 'html',
    ),
  );
}

function mymodule_print_links($nid=NULL) {
  ctools_include('ajax');
  ctools_include('modal');
  ctools_modal_add_js();

  $build['saveprogress_link'] = mymodule_save_progress_link($nid);

  return '<div id="level-form">' . drupal_render($build) . '</div>';
}

当我添加< span> #title 字段,它被转义,不会被解释为HTML。如何将此跨度(或其他标记)插入到链接类型表单元素的tile字段中。这个表单元素在Drupal网站上没有很好的记录。

When I add the <span> to the #title field, it's escaped and not interpreted as HTML. How can I insert this span (or other markup) to the tile field of a link type form element. This form element is not well documented on the Drupal site.

推荐答案

实际上比定制滚动主题要简单得多 - 只要告诉 drupal_render()'#title'作为html。

There's actually a much simpler way than custom-rolling a theme - just tell drupal_render() to treat '#title' as html.

function mymodule_save_progress_link($nid) {
  return array(
    '#type' => 'link',
    '#title' => '<span>unescaped HTML here</span> '.t('Save Progress'),
    '#href' => 'saveprogress/nojs/' . $nid,
    '#id' => 'saveprogress-link',
    '#ajax' => array(
      'wrapper' => 'level-form',
      'method' => 'html',
    ),
    '#options' => array(
      'html' => true,
    )
  );
}

这可能非常方便的添加图像或其他元素到点击区域。

This could be very handy for adding images or other elements to a click-able area.

这篇关于Drupal 7 - 在#link表单类型条目中添加HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆