- Patch #241364 by maartenvg, sun, effulgentsia: () not passed to hook_validate()/hook_node_validate(), and not passed by reference to hook_form().
parent
5d810f73e7
commit
3702347af9
|
@ -649,10 +649,12 @@ function hook_node_update_index($node) {
|
|||
* The node being validated.
|
||||
* @param $form
|
||||
* The form being used to edit the node.
|
||||
* @param $form_state
|
||||
* The form state array.
|
||||
*
|
||||
* @ingroup node_api_hooks
|
||||
*/
|
||||
function hook_node_validate($node, $form) {
|
||||
function hook_node_validate($node, $form, &$form_state) {
|
||||
if (isset($node->end) && isset($node->start)) {
|
||||
if ($node->start > $node->end) {
|
||||
form_set_error('time', t('An event may not end before it starts.'));
|
||||
|
@ -973,7 +975,8 @@ function hook_prepare($node) {
|
|||
* @param $node
|
||||
* The node being added or edited.
|
||||
* @param $form_state
|
||||
* The form state array. Changes made to this variable will have no effect.
|
||||
* The form state array.
|
||||
*
|
||||
* @return
|
||||
* An array containing the form elements to be displayed in the node
|
||||
* edit form.
|
||||
|
@ -987,7 +990,7 @@ function hook_prepare($node) {
|
|||
*
|
||||
* @ingroup node_api_hooks
|
||||
*/
|
||||
function hook_form($node, $form_state) {
|
||||
function hook_form($node, &$form_state) {
|
||||
$type = node_type_get_type($node);
|
||||
|
||||
$form['field1'] = array(
|
||||
|
@ -1112,10 +1115,12 @@ function hook_update($node) {
|
|||
* The node being validated.
|
||||
* @param $form
|
||||
* The form being used to edit the node.
|
||||
* @param $form_state
|
||||
* The form state array.
|
||||
*
|
||||
* @ingroup node_api_hooks
|
||||
*/
|
||||
function hook_validate($node, &$form) {
|
||||
function hook_validate($node, $form, &$form_state) {
|
||||
if (isset($node->end) && isset($node->start)) {
|
||||
if ($node->start > $node->end) {
|
||||
form_set_error('time', t('An event may not end before it starts.'));
|
||||
|
|
|
@ -926,7 +926,7 @@ function node_object_prepare($node) {
|
|||
/**
|
||||
* Perform validation checks on the given node.
|
||||
*/
|
||||
function node_validate($node, $form = array()) {
|
||||
function node_validate($node, $form, &$form_state) {
|
||||
$type = node_type_get_type($node);
|
||||
|
||||
if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
|
||||
|
@ -946,9 +946,18 @@ function node_validate($node, $form = array()) {
|
|||
form_set_error('date', t('You have to specify a valid date.'));
|
||||
}
|
||||
|
||||
// Do node-type-specific validation checks.
|
||||
node_invoke($node, 'validate', $form);
|
||||
module_invoke_all('node_validate', $node, $form);
|
||||
// Invoke hook_validate() for node type specific validation and
|
||||
// hook_node_validate() for miscellaneous validation needed by modules. Can't
|
||||
// use node_invoke() or module_invoke_all(), because $form_state must be
|
||||
// receivable by reference.
|
||||
$function = node_type_get_base($node) . '_validate';
|
||||
if (function_exists($function)) {
|
||||
$function($node, $form, $form_state);
|
||||
}
|
||||
foreach (module_implements('node_validate') as $module) {
|
||||
$function = $module . '_node_validate';
|
||||
$function($node, $form, $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,10 +80,7 @@ function node_form_validate($form, &$form_state) {
|
|||
// not update it with form values that have not yet been validated, so we
|
||||
// create a pseudo-entity to use during validation.
|
||||
$node = (object) $form_state['values'];
|
||||
node_validate($node, $form);
|
||||
|
||||
// Field validation. Requires access to $form_state, so this cannot be
|
||||
// done in node_validate() as it currently exists.
|
||||
node_validate($node, $form, $form_state);
|
||||
entity_form_field_validate('node', $form, $form_state);
|
||||
}
|
||||
|
||||
|
@ -137,8 +134,10 @@ function node_form($form, &$form_state, $node) {
|
|||
'#type' => 'hidden',
|
||||
'#default_value' => isset($node->changed) ? $node->changed : NULL,
|
||||
);
|
||||
// Get the node-specific bits.
|
||||
if ($extra = node_invoke($node, 'form', $form_state)) {
|
||||
// Invoke hook_form() to get the node-specific bits. Can't use node_invoke(),
|
||||
// because hook_form() needs to be able to receive $form_state by reference.
|
||||
$function = node_type_get_base($node) . '_form';
|
||||
if (function_exists($function) && ($extra = $function($node, $form_state))) {
|
||||
$form = array_merge_recursive($form, $extra);
|
||||
}
|
||||
if (!isset($form['title']['#weight'])) {
|
||||
|
|
Loading…
Reference in New Issue