- Generate the node editing form array.
File
- modules/node.module, line 1646
- The core that allows content to be submitted to the site.
Code
function node_form_array($node) {
node_object_prepare($node);
$form['#id'] = 'node-form';
foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => $node->$key,
);
}
$form['changed'] = array(
'#type' => 'hidden',
'#default_value' => $node->changed,
);
$form = array_merge_recursive($form, node_invoke($node, 'form'));
if (!isset($form['title']['#weight'])) {
$form['title']['#weight'] = -5;
}
$node_options = variable_get('node_options_' . $node->type, array('status', 'promote'));
if (!isset($node->nid)) {
foreach (array('status', 'moderate', 'promote', 'sticky', 'revision') as $key) {
$node->$key = in_array($key, $node_options);
}
global $user;
$node->uid = $user->uid;
}
else {
$node->revision = in_array('revision', $node_options);
}
$form['#node'] = $node;
if (user_access('administer nodes')) {
$form['author'] = array(
'#type' => 'fieldset',
'#title' => t('Authoring information'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 20,
);
$form['author']['name'] = array(
'#type' => 'textfield',
'#title' => t('Authored by'),
'#maxlength' => 60,
'#autocomplete_path' => 'user/autocomplete',
'#default_value' => $node->name ? $node->name : '',
'#weight' => -1,
'#description' => t('Leave blank for %anonymous.', array('%anonymous' => theme('placeholder', variable_get('anonymous', 'Anonymous')))),
);
$form['author']['date'] = array(
'#type' => 'textfield',
'#title' => t('Authored on'),
'#maxlength' => 25,
'#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => $node->date)),
);
if (isset($node->nid)) {
$form['author']['date']['#default_value'] = $node->date;
}
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Publishing options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 25,
);
$form['options']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#default_value' => $node->status,
);
$form['options']['moderate'] = array(
'#type' => 'checkbox',
'#title' => t('In moderation queue'),
'#default_value' => $node->moderate,
);
$form['options']['promote'] = array(
'#type' => 'checkbox',
'#title' => t('Promoted to front page'),
'#default_value' => $node->promote,
);
$form['options']['sticky'] = array(
'#type' => 'checkbox',
'#title' => t('Sticky at top of lists'),
'#default_value' => $node->sticky,
);
$form['options']['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $node->revision,
);
}
else {
foreach (array('uid', 'created') as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => $node->$key,
);
}
}
$form['preview'] = array(
'#type' => 'button',
'#value' => t('Preview'),
'#weight' => 40,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 45,
);
if ($node->nid && node_access('delete', $node)) {
$form['delete'] = array(
'#type' => 'button',
'#value' => t('Delete'),
'#weight' => 50,
);
}
$form['#after_build'] = array('node_form_add_preview');
return $form;
}
Login or
register to post comments