2014-04-01 18:55
浏览 77

自动填写Drupal 8标题?

I'm trying to auto-fill the title a content creation form in Drupal 8 with the user ID of the person creating the node, but I can't seem to get past step 1, which is having the title default to anything. I've made a module and added this code to it:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "new_content_type_node_form") {
    $form['title']['#default_value'] = 'Test12';

On the creation screen I'm using dpm to look at the $form var, and it's showing that the title does have a value in #default_value, and it is Test12, but when the form renders the title field is blank.

It seems like the way to do this in Drupal 7 and earlier was drupal_set_title(), but I can't find the equivalent for Drupal 8. Any ideas?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用此人的用户ID在Drupal 8中自动填充内容创建表单的标题 创建节点,但我似乎无法通过第1步,即标题默认为任何东西。 我已经创建了一个模块,并将此代码添加到其中:

  function mymodule_form_alter(& $ form,& $ form_state,$ form_id){
 if($ form_id  ==“new_content_type_node_form”){
 $ form ['title'] ['#default_value'] ='Test12'; 

在创建屏幕上,我使用 dpm 来查看 $ form var,它显示标题在#default_value中有一个值,它是Test12, 但是当表单呈现标题字段为空时。

在Drupal 7及更早版本中执行此操作的方式似乎是 drupal_set_title(),但我可以 找不到Drupal 8的等价物。任何想法?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufu9521 2014-04-01 22:19

    Solved by digging a little deeper into the form array:

    $form['title']['widget'][0]['value']['#default_value'] = 'Test12';
    点赞 评论

相关推荐 更多相似问题