background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount
Eric.London's picture

This code snippet will add a collapsible fieldset containing a preview of the node you are attempting to delete.

<?php
function MYMODULE_form_alter($form_id, &$form) {
  if (
$form_id == 'node_delete_confirm') {
   
$form['nodePreviewFieldset'] = array(
     
'#type' => 'fieldset',
     
'#title' => 'Preview',
     
'#weight' => 10,
     
'#collapsed' => TRUE,
     
'#collapsible' => TRUE,
    );
   
   
$form['nodePreviewFieldset']['nodePreview'] = array(
     
'#value' => node_view(node_load(arg(1)), TRUE, FALSE, FALSE)
    );
  }
}
?>

Here's a screenshot:

Eric.London's picture

Here's a way you can embed a node in a collapsible fieldset into another page callback:

<?php
function MYMODULE_MYFUNCTION() {
 
$page_contents = "";
 
// ...code...
 
$fieldset = array(
   
'#type' => 'fieldset',
   
'#title' => t('MYTITLE'),
   
'#collapsible' => TRUE,
   
'#collapsed' => TRUE,
   
'#value' => node_view(node_load(MYNODEID), TRUE, FALSE, FALSE),
  );
 
$page_contents .= theme('fieldset', $fieldset);
 
// ...code...
 
return $page_contents;
}
?>

Here is how you can add a CCK node form in a collapsible fieldset into a page callback...

<?php
function MYMODULE_MYFUNCTION() {
 
$page_contents = "";
 
// ...code...
 
$page_contents .= theme('fieldset',
    array(
     
'#title' => 'MYTITLE',
     
'#collapsible' => TRUE,
     
'#collapsed' => TRUE,
     
'#value' => drupal_get_form('MYCCKNODETYPE_node_form', array(
       
'type'=>'MYCCKNODETYPE',
       
'uid' => $GLOBALS['user']->uid,
       
'name' => $GLOBALS['user']->name)
      )
    )
  );
 
// ...code...
 
return $page_contents;
}
?>

Eric.London's picture
NOTE: this page has been replaced.

I wanted to embed a form in the page of a custom module to create a CCK node type. I thought it would be neat to enclose the form in a collapsible fieldset...

<?php
function MODULENAME_SOMEFUNCTION() {
 
$page_contents = "";
 
//...code...
 
$page_contents .= drupal_get_form('_MODULENAME_cck_form', 'MY_CCK_NODE_TYPE');
 
//...code...
 
return $page_contents;
}

function
_MODULENAME_cck_form($nodeType) {
 
$form = array();
  
 
// get a list of node types
 
$nodeTypes = node_get_types();
  
 
// create empty node
 
$node = array(
   
'type'    => $nodeType,
   
'uid'      => $GLOBALS['user']->uid,
   
'name'    => $GLOBALS['user']->name,
  );
  
 
// create the cck form fields
 
$form = content_form($node);

 
// get a list of node forms
 
$nodeForms = node_forms();
  
 
// get the callback for this node type
 
$nodeFormCallback = $nodeForms[$nodeType.'_node_form']['callback'];
  
 
// get the node form fields
 
$form = array_merge($form, node_form($node));
  
 
// add fieldset
 
$fieldset = array();
 
$fieldset[$nodeType] = array(
   
'#type' => 'fieldset',
   
'#title' => 'Add ' . $nodeTypes[$nodeType]->name,
   
'#collapsible' => TRUE,
   
'#collapsed' => TRUE,
  );
  
 
// add form to fieldset
 
foreach ($form as $k => $v) {
   
$fieldset[$nodeType][$k] = $v;
  }
  
  return
$fieldset;
}
?>

Syndicate content