Questions tagged [drupal-hooks]

In Drupal terminology, the PHP functions used to extend the functionality of Drupal core modules or third-party modules are called hooks.

Hooks are just normal PHP functions which allow a user to extend functionality within Drupal. They are used by Drupal core, and contributed modules. More information can be found at api.drupal.org, which has a page listing all the hooks used by Drupal core code.

Implementing hooks

To implement a hook you must create a module, and add a hook function to it. The actual hook implementation function name will replace the word 'hook' in the function name with the name of your custom module. Thus hook_query_alter() becomes mymodule_query_alter(). Drupal maintains a list of all included hooks for the site by searching the enabled modules for functions using that naming pattern.

143 questions
8
votes
1 answer

Drupal: Are hook_ functions in *.api.php ever called?

In Drupal 7, every core module has a *.api.php file, where * is the name of the module. For example modules/node/node.api.php modules/path/path.api.php What are these files for? They contain functions that start with hook_, and the name of a hook…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
8
votes
2 answers

Using preprocess hook on specific node type in Drupal 8

I've had success using preprocess page hooks such as: function mytheme_preprocess_page__node_front(&$variables) { ... } and function mytheme_preprocess_page__node_12(&$variables) { ... } which correlate with custom templates named…
ConorBaumgart
  • 493
  • 1
  • 3
  • 18
7
votes
1 answer

Combine like products on the same line item in the cart

I am having the same issue as outlined here but the solutions below do not work. I do have "Commerce Product Option" enabled. I also alter the price using this hook, function mectronic_get_amount_qty($price, $length) { //print '
P ' .…
Alex Borsody
  • 1,908
  • 9
  • 40
  • 74
5
votes
2 answers

Create a template for the page

Let's say I have this implementation of hook_menu(): function example_menu(){ $items = array(); $items['admin/recent-completions'] = array( 'title' => 'Recent Completions (Last 100)', 'page callback' => 'example_recent', …
Chris Muench
  • 17,444
  • 70
  • 209
  • 362
4
votes
1 answer

Drupal save data hook_form_alter

I added a field to a node using hook_form_alter and i can see it fine but now i would like of course that the data enterd in that field is also saved. What do i have to do for this to happen?
dazz
  • 8,162
  • 9
  • 31
  • 41
4
votes
2 answers

What Ties a Drupal Hook to a Particular Module?

What Ties a Drupal Hook to a Particular Module? In Drupal 7, every core module has an "api" file $ ls modules/*/*.api.php modules/aggregator/aggregator.api.php modules/openid/openid.api.php modules/block/block.api.php …
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
4
votes
2 answers

Where is Drupal's Module Hook Calling Started?

In a Drupal 7 (and Drupal 6?) system, what "kicks off" the hook calling process, or where are "top level" hook calls located? As I currently understand the Drupal module system, any module is capable of creating a hook for another module to…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
4
votes
1 answer

Drupal 8 add javascript and pass data in a hook with custom module

I am building a custom module with Drupal 8. One of the requirements of the module is that it sets up a javascript file based on the configuration settings, which the user of the module sets up in module configuration. The javascript which needs to…
software_writer
  • 3,941
  • 9
  • 38
  • 64
4
votes
1 answer

What's the point to have hook_mail_alter if I already have hook_mail?

What's the point to have hook_mail_alter if I already have hook_mail? For example, I saw that hook_mail_alter is used to add a footer to my mail message. But I could use hook_mail() to add it, instead of using 2 functions… What am I missing? Maybe…
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
4
votes
1 answer

drupal :: order complete hook and upgrade user permission/roles

I want to be able to upgrade user's permission after the order status shows complete. I figured out that I should use hook_order hook in order to achieve that. But how do I get to know which user has created that order and how do go about updating…
Nikhil
  • 1,268
  • 2
  • 13
  • 29
4
votes
1 answer

Drupal-7 how to get hook_field_[formatter_]prepare_view() invoked without overwriting existing formatter

From my module, I'm looking for a way to change text-fields value during rendering process, but WITHOUT creating a new formatter, and BEFORE the currently affected formatter works. In other words I want my changes always made on any text-field, as a…
cFreed
  • 4,404
  • 1
  • 23
  • 33
3
votes
2 answers

Drupal 7 hook_node_access to conditionally block node access

For all users I need to conditionally block access to nodes of type 'message'. The only way users should be able to view these message nodes is by successfully submitting a form. I've started like this: function mymodule_node_access($node, $op,…
pragnatek
  • 51
  • 1
  • 5
3
votes
2 answers

hook_load/hook_view not called

I have a module with four node types declared. My problem is, hook_load, hook_view is never called. I used drupal_set_message to find out if certain hook is being called. And I found out hook_load, hook_view isn't. Just to give you clear picture,…
Andrew
  • 1,035
  • 7
  • 22
  • 40
3
votes
2 answers

hook_menu() - an unexpected behaviour (longer path issue)

I am initializing a number of items via hook_menu (Drupal 6) ... $items['webtv/block/%/playlist/edit/%'] = array( ... 'page arguments' => array('webtv_playlist_form', 2, 5), ... ); $items['webtv/block/%/playlist/edit/%/filter/new'] = array( …
Shoaib Nawaz
  • 2,302
  • 4
  • 29
  • 38
2
votes
1 answer

How can I pass a parameter to the form submit handler in Drupal

I am working on a module which is common for a number of forms. I need to pass the $form_id as a parameter to the submit handler and set the form values accordingly in the submit function. function ppi_form_alter(&$form, &$form_state, $form_id){ …
perpetual_dream
  • 1,046
  • 5
  • 18
  • 51
1
2 3
9 10