Drupal 7 - 以编程方式向节点添加自由标记

标签 drupal drupal-7 drupal-taxonomy

我正在尝试以编程方式将一些标签添加到节点的免费标记分类字段中。 假设我有以下节点结构,

<?php

$my_tag = 'test';

$node = (object) array(
  'type' => $node_type,
  'nid' => $row->nid,
  'vid' => $row->vid,
  'uid' => 1,
  'status' => $row->status,
  'language' => $row->language,
  'created' => $row->created,
  'changed' => $row->changed,
  'comment' => $row->comment,
  'promote' => $row->promote,
  'title' => $row->title,
  'teaser' => $row->teaser,
  'field_custom_tags' => //TODO add $my_tag to this free tagging taxonomy field
);

$node = node_submit($node);
node_save($node);

?>

最佳答案

在 Drupal 7 中,您不需要以编程方式执行此操作。只需使用小部件类型“自动完成”将分类术语字段添加到您的内容类型 - 然后单击“编辑”并选择默认标签。

你已经完成了,除非你想从内容输入表单中隐藏该字段(这是一个单独的问题,在这里回答:How to hide a field on node data entry form in drupal?)

Screen Shot of Default Tags

关于Drupal 7 - 以编程方式向节点添加自由标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426879/

相关文章:

drupal-7 - 不允许 :/sites/default/files/not working for my Drupal Website

Drupal 6 - 添加分类术语后重定向

Drupal 7 到 Drupal 8 : migrate taxonomy with translation (i18n)?

drupal - 如何在drupal中获取所有分类子ID

php - 在 drupal 中覆盖内容页面的更好方法

mysql - Drupal 7查询条件NOT LIKE

javascript - Drupal 7 Form api 使用 Jquery 自定义 javascript

php - 文件上传返回值

mysql - Drupal 8 没有连接到 Docker 中的 Mysql

php - 使用 API 将节点添加到 Drupal