dousong4777 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?

  • 写回答

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';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记