Changing the Node Creation Title in Drupal?

醉酒当歌 提交于 2020-01-02 11:29:17

问题


Let's say I have a node called "product". When I create such a node, it will always display: "Create product" as the title of the node. How do I change this title WHEN CREATING THE NODE?


回答1:


you mean you have a content type "product"?

the "Create product" title when creating a node of type "product" is set in node_add($type):

// ...
drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)));
$output = drupal_get_form($type .'_node_form', $node);
// ...

there are at least 2 options to change this:

  • change the translatable string 'Create @name' (indicated by the t() it is passed through) via
    • settings.php - search for locale_custom_strings_, or
    • http://drupal.org/project/stringoverrides
  • modify the 'product_node_form' as mentioned by gpilotino (minus the $form['title']['#title'] = 'foobar' - you only need the drupal_set_title('foobar')). this is a little harder, as you have to write your own module.



回答2:


This should do the trick in your custom module, just be specific to the content type.

 function your_module_form_alter(&$form, $form_state, $form_id) {
      if ($form_id == 'contenttype_node_form') {
        drupal_set_title(t("Title you prefer"));
      }
    }



回答3:


Try this if none of the above has worked:

function YOUR-THEME_process_page(&$variables) {
  if (arg(0) == 'node' && arg(1) == 'add') {
    switch(arg(2)) {
      case 'YOUR-CONTENT-TYPE':
       $variables['title'] = t('New Record');
    }
  }
}



回答4:


try with

yourmodule_form_product_node_form_alter(&$form, $form_state)
{
  drupal_set_title($foobar);
}



回答5:


I assume you mean that you want to change the words "Create Product"

For a quick and easy solution you can use the [string override][1] module. It is a little bit of a hack but it is simple and has a nice UI for changing this - there is something to be said for simplicity :-)

[1]: http://drupal.org/project/stringoverrides string overrides




回答6:


I contributed a module that solves this problem. Check out Node Add Title.

Hope it helps.




回答7:


try this,

function hook_node_view($node, $view_mode, $langcode) { 
  if (arg(0) == 'node') {
  $nid = arg(1);
  .
  .
  .
  .
  drupal_set_title($title);
}  

}

It's Work.

Thanks, Latika S.



来源:https://stackoverflow.com/questions/1392573/changing-the-node-creation-title-in-drupal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!