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 Anonymous (not verified) on
hello, how can i get the hook of a custom block ?
Comments
This question doesn't make
This question doesn't make sense in Drupal terminology, and you have provided basically no information about what you are trying to do. Maybe this can help.
hook_block_accesshook_block
Updated
hook_block_cid_parts_alter
hook_block_configure
hook_block_info
hook_block_info_alter
hook_block_list_alter
hook_block_save
hook_block_view
hook_block_view_alter
hook_block_view_MODULE_DELTA_alter
Here is the full list of hooks: https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7.x
And how can i get the machine
And how can i get the machine name of the block ?
Sorry, my answer is not for
Updated
There are two types of blocks:
1. Block that created with UI.
2. Block created with custom module.
To get the id (delta) of a block created with UI, open 'configure' window and see the url.
For instance, if the url is:
/admin/structure/block/manage/block/1/configure
Then the block id (delta) is 1.
See the screenshots:
https://i.imgur.com/7cXCsdQ.png
https://i.imgur.com/5ruOH3r.png
The id (delta) of a custom block is array key which is used in hook_block_info().
For instance if we create a custom block like this:
Then the block id (delta) is 'my_custom_block'.
Now you can use this id (delta) to output some content.
(!!! Attention: this isn't work for the blocks created with UI, but only for custom blocks).
The example
You can alter the both types of blocks using hook_block_view_alter().
The example
For additional info see 'Building Custom Blocks with Drupal 7'.