【问题标题】:How to programmatically select list (text) field in Drupal 8?如何以编程方式选择 Drupal 8 中的列表(文本)字段?
【发布时间】:2016-01-15 02:54:26
【问题描述】:

我已经使用 Drupal 8 Node::create 以编程方式成功创建了节点,并且能够正确选择列表(整数)字段,如下所示,但列表(文本)字段没有通过相同的过程被选中。任何帮助表示赞赏。

(管理字段)

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

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

'field_expires_in_days_ 的允许值列表

30|30
60|60
90|90

“field_item_type”的允许值列表

tipsheet|Tip Sheet
fyi|FYI
video|Video

(控制器)

$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

【问题讨论】:

    标签: php drupal drupal-7 content-management-system drupal-8


    【解决方案1】:

    键'field_item_type'中有一个空格

    【讨论】:

    • OMG...这是惊人的发现...我使用的是 Notepad++,但似乎没有发现...是否有任何 IDE 或代码编辑器推荐用于 PHP 或专门用于 Drupal ?
    • PHPStorm,最好的,但你必须付费。 netbean 是免费的,但不如 PHPstorm
    猜你喜欢
    • 2013-06-07
    • 1970-01-01
    • 2016-03-19
    • 2016-02-28
    • 2017-09-28
    • 2018-06-27
    • 2021-10-05
    • 2010-10-13
    相关资源
    最近更新 更多