function gnode_node_add in Group 7
Adds group data to the node add form.
Parameters
Group $group: The group to create the node for.
string $node_type: The type of node to create for the group.
Return value
array Returns the node editing form.
See also
node_add()
1 string reference to 'gnode_node_add'
- gnode_menu in modules/
gnode/ gnode.router.inc - Implements hook_menu().
File
- modules/
gnode/ gnode.module, line 264 - Contains Group's implementation of the Node module hooks and forms.
Code
function gnode_node_add(Group $group, $node_type) {
global $user;
// Create an empty node to pass on to the node form.
$types = node_type_get_types();
$node = (object) array(
'uid' => $user->uid,
'name' => isset($user->name) ? $user->name : '',
'type' => $node_type,
'language' => LANGUAGE_NONE,
'group' => $group->gid,
);
// Set the page title to something different than the local action title.
$message = 'Create @name in @group';
$replace = array(
'@name' => $types[$node_type]->name,
'@group' => $group
->label(),
);
drupal_set_title(t($message, $replace), PASS_THROUGH);
// Build the arguments to set in the form state. We ensure any extra URL
// parameters will be passed on to the form builder as well. For instance:
// group/1/node/add/page/specialvar will pass on the empty 'page' node as well
// as the string "specialvar".
$setup = array(
$node,
);
$extra = array_slice(func_get_args(), 2);
$args = array_merge($setup, $extra);
// Build the form state, paying extra attention to two things: setting the
// arguments as explained above and making sure the form will know to load
// node.pages.inc whenever it's rebuilt.
$form_state['build_info']['args'] = array_values($args);
form_load_include($form_state, 'inc', 'node', 'node.pages');
// Finally we build the form with our customized form state.
return drupal_build_form($node_type . '_node_form', $form_state);
}