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

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

问题描述

我需要将 HTML 标记添加到 Drupal 7 #type 链接表单元素的 #title 字段.输出应大致如下:

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表单,我不能只使用#markupl()函数.这是一个没有跨度的示例:

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.如何将此跨度(或其他标记)插入到 link 类型表单元素的 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天全站免登陆