Drupal 7 - 在#link 表单类型条目中添加 HTML?

标签 drupal drupal-7 drupal-forms

我需要将 HTML 标记添加到 #title Drupal 7 领域 #type链接表单元素。输出应该大致如下所示:

<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()功能。这是一个没有跨度的示例:

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 的平铺字段中类型表单元素。这个表单元素在 Drupal 网站上没有很好的记录。

最佳答案

实际上有一种比自定义滚动主题更简单的方法 - 只需告诉 drupal_render()'#title' 视为 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,
    )
  );
}

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

关于Drupal 7 - 在#link 表单类型条目中添加 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15121231/

相关文章:

php - Drupal 7 主题 "front"与其他页面不同

drupal - 如何将自定义表单添加到自定义模块中的自定义 block

php - Drupal 7默认用户注册表单如何实现多步

html - 在一个 css 声明中捕获所有文本

css - 我怎样才能用里面的文字创建一个圆圈?

drupal - Drupal:使用l()创建仅 anchor 链接

mysql - 我希望这些行针对我的数据库的所有值运行

html - 我如何将 css 添加到 drupal 7 View

javascript - Galleria 模块 - 样式顶部 :

drupal - 如果用户属于某个角色,如何在用户登录后将用户重定向到特定页面?