6

I wonder how to add a button or link to perform an action of _create_node function. I understand on how to do it on the node edit screen, but not the display.

I want a button of create "new item" on the node display. I'm creating a custom module to create the new node, but need a button to call it.

Any suggestions?

2
  • Is your requirement is to add button in node display..??
    – Abin
    Jan 16, 2016 at 6:21
  • Yeah that is what i'm trying to do. I want a button of create "new item" on the node display. I'm creating a custom module to create the new node, but need a button to call it. Not sure where to go from here.. Jan 17, 2016 at 4:59

2 Answers 2

7

You can implement the hook_node_view() like the following code:

function YOUR_MODULE_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'CONTENT_TYPE_NAME') {
    $form = drupal_get_form('redirect_button_form');
    $node->content['redirect_button'] = $form;
 }
}

function redirect_button_form($form, &$form_submit) {
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('New Item'),
    );
    return $form;
}

function redirect_button_form_submit($form, &$form_state) {
    //here the path where you need to go
    $path = 'node/add/CONTENT_TYPE_NAME';
    drupal_goto($path);
}
2
  • This is the correct answer to my question, thank you. Jan 19, 2016 at 2:53
  • @ThroneDigital a pleasure, and god luck in your projects Jan 19, 2016 at 2:56
2

For adding any custom link/button on node display, try by adding your code in tpl file. For customizing node display add your code in node.tpl.php.

For tpl naming conventions and more details, Please refer

  1. Theming nodes by content type.
  2. Drupal 7 Template (Theme Hook) Suggestions

Hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.