7

I tried:

mymodule_form_node_alter

mymodule_form_node_form_alter

and global hook:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form['#id'] == 'node-form') {
      #set message
  }
}

None from above works for me.

I need to create hook that invokes on every node form. if it possible.

11
function yourmodule_form_alter(&$form, &$form_state, $form_id) {
    if (strpos($form_id, '_node_form') !== FALSE) {
      // ...
    }
}
20
/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function MYMODULE_form_node_form_alter(&$form, &$form_state) {
  // do staff
}

It could not work because you have to clear caches after adding the hook.

  • This is the right way to target node forms in D7..!! – Devendra Jadhav Mar 2 '15 at 11:37
2

Use hook_form_BASE_FORM_ID_alter() to provide a form-specific alteration for shared forms. For your example this would be:

function yourmodule_form_node_form_alter(&$form, &$form_state, $form_id) {
  // code that runs on every node form
}

https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_BASE_FORM_ID_alter/7

1

I find better solution:

if (isset($form['#node'])) {

}

Another solution is to use: hook_form_BASE_FORM_ID_alter()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.