简体   繁体   English

如何在Drupal 8中以编程方式选择列表(文本)字段?

[英]How to programmatically select list (text) field in Drupal 8?

I have successfully created node programmatically using Drupal 8 Node::create and be able to select list (integer) field correctly as following, but list (text) field is not getting selected with the same process. 我已经使用Drupal 8 Node :: create成功地以编程方式创建了节点,并能够按照以下方式正确选择列表(整数)字段,但是列表(文本)字段未通过相同的过程选择。 Any help appreciated. 任何帮助表示赞赏。

(Manage Fields) (管理字段)

LABEL   MACHINE NAME    FIELD TYPE
===========================

    Expires (in Days)   field_expires_in_days_  List (integer) -> NOT WORKING
    Item Type   field_item_type List (text) - Working

Allowed value list for 'field_expires_in_days_ “ field_expires_in_days_”的允许值列表

30|30
60|60
90|90

Allowed value list for 'field_item_type' “ field_item_type”的允许值列表

tipsheet|Tip Sheet
fyi|FYI
video|Video

(Controller) (控制器)

$newListItem = array(); //prepare new item
$newListItem["title"] = "Title 111";
$newListItem["summary"] = "Some description";
$newListItem["itemType"] = "tipsheet";
$newListItem["expiresInDays"] = "30";

$node = Node::create([
'type' => 'custom_content_type',
'status' => 1,
'title' => $listItem['title'],
'body' => $listItem['summary'],
'field_item_type ' => $listItem['itemType'],
'field_expires_in_days_' => $listItem['expiresInDays'],
]);
$node->save();

https://www.drupal.org/node/2650648 https://www.drupal.org/node/2650648

键' field_item_type '中有一个空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Drupal字段:以编程方式插入选择列表选项 - Drupal fields: Programmatically insert select list options 如何在Drupal 7中以编程方式设置具有OR功能的条件字段 - How to programmatically set a conditional field with OR functionality in Drupal 7 Drupal - 如何以编程方式更新CCK NodeReference字段? - Drupal - How to update a CCK NodeReference field programmatically? 如何在AJAX处理程序Drupal 8中以编程方式为Paragraph字段创建新的小部件 - How to create a new widget for a Paragraph field programmatically in an AJAX handler Drupal 8 如何在Drupal 7中以编程方式获取具有特定字段的所有内容类型? - How to get all content types having a certain field programmatically in Drupal 7? 在 Drupal 8 的文本字段中集成选择下拉菜单 - Integrate a select pull-down in a text field in Drupal 8 以编程方式设置 Drupal 节点选择列表字段值 - Setting Drupal node select list field value programatically 以编程方式创建drupal节点并设置自定义选择列表字段 - Create drupal node programatically and set custom select list field 以编程方式在drupal7中显示文件字段PDOException _display - file field programmatically PDOException _display in drupal7 在drupal 7中使用hook_field_widget_form将级联选择列表作为自定义字段 - Cascaded select list as a custom field using hook_field_widget_form in drupal 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM