Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By victor.novtis on
Hi,
I'm verifying all process of Drupal 7 x, concluded that the start the process of save button in custom node, start this method in file ../modules/node/node.pages.inc, line 457, with o method node_form_submit:
<?php
function node_form_submit($form, &$form_state) {
// I need verify if the data already exists in table, with field customs.
// If exists, show the message - drupal_set_message(t('@type % The data already exist!!!!!!!!!!!!!!', $t_args));
$node = node_form_submit_build_node($form, $form_state);
$insert = empty($node->nid);
node_save($node);
$node_link = l(t('view'), 'node/' . $node->nid);
$watchdog_args = array('@type' => $node->type, '%title' => $node->title);
$t_args = array('@type' => node_type_get_name($node), '%title' => $node->title);
if ($insert) {
watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
drupal_set_message(t('@type %title has been created.', $t_args));
}
else {
watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
drupal_set_message(t('@type %title has been updated.', $t_args));
}
if ($node->nid) {
$form_state['values']['nid'] = $node->nid;
$form_state['nid'] = $node->nid;
$form_state['redirect'] = node_access('view', $node) ? 'node/' . $node->nid : '<front>';
}
else {
// In the unlikely case something went wrong on save, the node will be
// rebuilt and node form redisplayed the same way as in preview.
drupal_set_message(t('The post could not be saved.'), 'error');
$form_state['rebuild'] = TRUE;
}
// Clear the page and block caches.
cache_clear_all();
}
?>
How proceed in the case? Using hook (I did not make it call hook), writing into of code in method 'node_form_submit'...
Thanks,
Victor Oliveira.
Comments
No, no, no. This is very
No, no, no. This is very wrong. Don't edit core files.
The function you need to implement is:
https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function...
Here is a short tutorial how to implement a hook:
https://www.drupal.org/docs/7/creating-custom-modules/writing-comments-a...
Good luck.
I like cookies!