Last active
December 28, 2015 17:09
-
-
Save thirdender/7533792 to your computer and use it in GitHub Desktop.
Build a Drupal 7 node form using the FAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This leverages the node and form APIs to output a node add form. It can be | |
* used as part of a hook_menu page callback, or output in any part of the | |
* page. | |
*/ | |
// Create the empty $node object (replace CONTENT_TYPE with the machine name | |
// of your node type) | |
$node = new StdClass(); | |
$node->type = 'CONTENT_TYPE'; | |
$node->language = LANGUAGE_NONE; | |
$node->uid = $user->uid; | |
$node->name = isset($user->name) ? $user->name : 'anonymous'; | |
node_object_prepare($node); | |
// Build a dummy $form_state | |
$form_state = array(); | |
$form_state['build_info']['args'] = array($node); | |
// Ensure that node.pages.inc is included every time $form is processed | |
form_load_include($form_state, 'inc', 'node', 'node.pages'); | |
// Voilà! Il est sous $form! | |
$form = drupal_build_form("{$node->type}_node_form", $form_state); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment