【问题标题】:Setting Drupal node select list field value programatically以编程方式设置 Drupal 节点选择列表字段值
【发布时间】:2016-03-28 22:44:53
【问题描述】:

我有一个带有自定义字段的 Drupal 7 节点。我可以通过附录 1 中的代码以编程方式成功地将单个值设置为选择列表字段。但我想为这个选择列表分配多个值。 (它已被配置为在后端接受多个值。)

问题:

以编程方式将选择列表中的多个值分配给 Drupal 节点的正确语法是什么?

我尝试过的代码:

$node->field_referee_status[LANGUAGE_NONE][0]['value'] = 'pending', 'declined';

以上代码导致以下错误:

*Parse error*:  syntax error, unexpected ',' in
*/home/scienceorg/public_html/sites/all/modules/rules/modules/php.eval.inc(125)
: eval()'d code* on line *77*

附录 1:

$node->field_referee_status[LANGUAGE_NONE][0]['value'] = 'pending';

【问题讨论】:

    标签: php drupal


    【解决方案1】:

    你想要这样的东西:

    $node->field_referee_status[LANGUAGE_NONE][0]['value'] = 'pending';
    $node->field_referee_status[LANGUAGE_NONE][1]['value'] = 'declined';
    

    如果您需要遍历许多项目,显然可以在循环中实现这一点

    【讨论】:

      猜你喜欢
      • 2013-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-10
      相关资源
      最近更新 更多