1

Just wondering if is there a way to expose the edit form of a page just below the page itself in the frontend.

Let's say I have the page Services, if you click a the edit tab you go to the admin page where you have the fields title and body for this page, here you can change its values and save.

I need to show the edit form (fields title, body and the button save) in the frontpage, just at the bottom of the page.

UPDATE: base in neok's answer: But I can not use $output var in utilities_block_view($delta = '') {

    function utilities_preprocess_page(&$variables, $arg, $delta=0) {

      if(arg(0) == 'node' && is_numeric(arg(1))) {        
        $nid = arg(1);
        //you need to include node.pages
        module_load_include('inc', 'node', 'node.pages');
        $output = node_page_edit(node_load($nid));

        return $output;
      }
    }


    function utilities_block_info() {    
      $blocks['edit_node_form'] = array(
        // info: The name of the block.
        'info' => t('Edit node Form'),
      );

      return $blocks;
    }


    function utilities_block_view($delta = '') {
      // The $delta parameter tells us which block is being requested.
      switch ($delta) {
        case 'edit_node_form':
          // Create your block content here
          $block['subject'] = t('Edit node Form');
          $block['content'] = $output;
          break;
      }

      return

 $block;
}
| improve this question | | | | |
5

You can output edit form of current node with node_page_edit function. So you can create a block programmatically(show this block only on node pages of your content type - Services for example) and output edit form with node_page_edit.

  if(arg(0) == 'node' && is_numeric(arg(1)) {        
    $nid = arg(1);
    //you need to include node.pages
    module_load_include('inc', 'node', 'node.pages');

    $output = node_page_edit(node_load($nid));
    return $output;
  }

Here you can find an example how create block.

| improve this answer | | | | |
  • thank neok, so I need to add the code to create the block? Can you pls elaborate? – chefnelone Jul 3 '13 at 11:06
  • @chefnelone That would be a separate question, but creating a block in code is very well documented; a quick Google search will get you everything you need – Clive Jul 3 '13 at 11:08
  • @Clive Sorry, I didn't made my question clear. I know how to create a block, I just need to know if the code to create the block goes before or after the line: "return $output". – chefnelone Jul 3 '13 at 11:23
  • Instead of return $output you'd have something like $block['content'] = $output; inside an implementation of hook_block_view(). node_page_edit() returns a form so that should do the trick nicely – Clive Jul 3 '13 at 11:24
  • @neok Do I have to put this code in preprocess page function? – chefnelone Jul 3 '13 at 13:51

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.