我想通过在 Drupal 8.7.6 中使用 hook_form_alter 有条件地更改附加到节点的纯文本字段的小部件。
function mymodule_form_node_article_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$options=[
'test1' => 'AAA',
'test2' => 'BBB',
'test3' => 'CCC',
'test4' => 'DDD',
];
$form['field_testdrop']['widget'][0]['#type']='select';
$form['field_testdrop']['widget'][0]['#options'] = $options;
}
但是,在尝试保存节点时,出现以下错误:
错误:无法在 Drupal\Component\Utility\NestedArray::setValue()(core/lib/Drupal/Component/Utility/NestedArray.php 的第 155 行)中创建指向/来自字符串偏移的引用。
我能做些什么来防止这种情况发生?