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步,即标题默认为任何东西。 我已经创建了一个模块,并将此代码添加到其中:</ p>

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

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

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

1条回答 默认 最新

相关推荐 更多相似问题