node_example_form
developer/examples/node_example.module, строка 91
- Версии
- 5 – 6
node_example_form(&$node)
Реализация hook_form()
.
Сейчас пора описать форму для накопления специфичной информации для этого типа ноды. Этот хук требует нас вернуть массив с вложенным в него массивом содержащим информацию для каждого элемента в форме.
Код
<?php
function node_example_form(&$node) {
$type = node_get_types('type', $node);
// We need to define form elements for the node's title and body.
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
);
// We want the body and filter elements to be adjacent. We could try doing
// this by setting their weights, but another module might add elements to the
// form with the same weights and end up between ours. By putting them into a
// sub-array together, we're able force them to be rendered together.
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#required' => FALSE
);
$form['body_filter']['filter'] = filter_form($node->format);
// Now we define the form elements specific to our node type.
$form['color'] = array(
'#type' => 'textfield',
'#title' => t('Color'),
'#default_value' => $node->color
);
$form['quantity'] = array(
'#type' => 'textfield',
'#title' => t('Quantity'),
'#default_value' => $node->quantity,
'#size' => 10,
'#maxlength' => 10
);
return $form;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии