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
2
votes
1 answer

How to prevent modify and view user profile in Drupal 7?

I would like to prevent specific user (or user group) to modify its profile in Drupal 7. That means that I would like to hook some function on the event when the user is about to display and change his profile. The best solution would be if he even…
majvan
  • 51
  • 6
2
votes
2 answers

Where to implement hook_search_info & _execute in order to force a language filter onto search results?

At the moment I am trying to force "current language" onto the list of the options passed into node_search_execute. Unfortunately I'm having trouble finding the right place to put the function hooks. Perhaps I am missing something simple. I've…
Alex C
  • 16,624
  • 18
  • 66
  • 98
2
votes
1 answer

How to add weight on hook_form_alter

I have a hook_form_alter in my module, but another module, workbench_access, also has a hook_form_alter which I need to be called before my hook_form_alter. How do I add weight to my hook_form_alter?
samwell
  • 2,757
  • 9
  • 33
  • 48
2
votes
2 answers

Implementing hook_user_insert doesn't login my user

I'm trying to forward the users to a specific page after they create their account, but when they get there, they are not logged in. function mymodule_user_insert(&$edit, $account, $category) { drupal_goto("node/3"); } Should I add something to…
2
votes
1 answer

Use dynamic e-mail generation in hook_mail()

Is it possible to dynamically generate cases in PHP switch statements, as in this example of hook_mail() ? /* * Implement hook_mail(). */ function rsvp_mail($key, &$message, $params) { $guests = rsvp_query(); foreach ($guests as $account) { …
starsinmypockets
  • 2,264
  • 4
  • 34
  • 45
2
votes
1 answer

Drupal hook that runs when modules are installed and uninstall?

I am trying to get a Drupal to run a custom hooks; one that needs to run when a module is being installed and another for when the module is being unistalled. Is there a hook or a trigger that I can use to have Drupal run the hook while the module…
2
votes
1 answer

What Core Drupal functions can be used to invoke hooks?

This is a followup to another question I asked abou creating your own hooks. In the answer and comments, two functions were mentioned module_invoke_all(...) drupal_alter(...) The function module_invoke_all appears to be used to invoke a hook for…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
2
votes
2 answers

Drupal 8 hook_form_alter not called in the search block form

I am trying to modify the form action of the search block in my Drupal 8 project. The search block is placed in the Primary menu area. I added the following code in my .theme file function mytheme_form_alter(&$form, FormStateInterface $form_state,…
Pramod Sivadas
  • 873
  • 2
  • 9
  • 28
2
votes
0 answers

Create database fields to an existing table when installing a module in Drupal 8

I'm new to drupal and I need some help. I created a new module with name user_extra. Which create necessery table when Installing the module. But I also need to insert some database field in 'users_field_data' table ('user_extra_id' and…
2
votes
3 answers

Search hook for filtering results?

I have been going through the docs and source code looking for something without luck. Is there a Drupal 6 hook that gets called after hook_search(), but before the $results gets handed off to the template system? I need to do a fairly custom…
mpdonadio
  • 2,891
  • 3
  • 35
  • 54
2
votes
1 answer

Using variable_set, hook block and hook menu to save config values then print out in custom template

I am trying to 1) implement the hook menu and variable_set in the block hook and to solicit and store configuration values from user, 2) then use retrieve configuration values and 3) pass them out into a template using theme hook when page is…
bert
  • 287
  • 6
  • 14
2
votes
1 answer

how to use function of My Sql in hook view query alter in drupal7

I am using views_query_alter for alter query of view. In my query I want condition like DATE_FORMAT(FROM_UNIXTIME(field_data_field_hiddeneventdate.field_hiddeneventdate_value), '%m') = '06'. But when I am trying $condition = array('field' => …
2
votes
1 answer

Print a 'node/add' form in a lightbox with Drupal

I'm having some troubles printing a 'node/add' form in a lightbox. I have in my custom.module a hook_menu like this: $items['get-form/%'] = array( 'title' => t('Get a form'), 'description' => t('Get form'), 'page callback' =>…
Ignacio Sánchez
  • 409
  • 4
  • 14
2
votes
1 answer

Wildcard Loader function called multiple times (_load)

I have a loader function which is called excessively whenever the user accesses the page. Naturally, I only need it to run once per page request, instead, it is called multiple times. Earlier the _load() ran only twice with MENU_CALLBACK, then I…
Saahir Foux
  • 654
  • 4
  • 12
  • 27
2
votes
1 answer

Drupal 6 : how to display a node?

I'm currently developing a module for Drupal 6, in which I have created a custom content type. I'm able to create/update/delete a node of this content type by using hook_form, hook_insert and so on. Now what I want is displaying the node when I…
Lo'
  • 95
  • 1
  • 1
  • 10
1
2
3
9 10