hook

Drupal 8: Creating Hook Alters programatically with Example

The Hook system will provide alter any content from one function from another in Drupal. The Drupal 8 Hook implementation are invoked with help of Core Drupal class function of moduleHandler(). This function will provide the object to execute all hook functions to alter the content.

Drupal 7: Creating custom Permissions hook_permission() with Example

Permissions control access in Drupal system. We can able to specify the permissions based on User Roles. We can programmatically able to create custom permissions by implementing the hook_permission in Drupal 7. The below is the syntax and example of how to use custom permissions. Once permissions are defined the need to clear cache. So, that permission available on admin/people/permissions page.

Drupal 7: Creating custom pages, forms using hook_menu()

The hook_menu() is the menu router for the Drupal system. In this hook we can able to specify the possible URL paths to our Drupal system. This function implementation must return the associative array of URL paths and their respective callbacks. The below is the syntax and usage example of this hook. Once you have implemented hook needs to flush the cache to detect system.

Drupal 7: Writing your custom table hook_schema() with Example

In Drupal hook_schema() help to create the Tables in Drupal system. This schema is defined in MODULE_NAME.install file. This hook invokes during the Module install. Similarly, during module uninstall tables defined in hook_schema() automatically get deleted. The below is the syntax and example of implementing hook_schema().

Drupal Inline Entity Form Module hook_form_alter()

The Inline entity form is the Drupal Contribute module. Which help to embed a entity form into another entity. Example: Commerce product add form cam be used in Node form. This module will help to create, update and delete entity based on its parent entity. This module embed entity form as the object to its parent form. To alter this specific entity form there is hook called hook_inline_entity_form_entity_form_alter(). Below is the syntax and example to usage of hook_inline_entity_form_entity_form_alter() to alter inline forms.

Drupal 7 : Creating custom hook for user defined functions with sample code

In Drupal HOOK are used to alter values or construct values to program. It similar to implementing class in Object Oriented Concepts. In Core and Contributed modules create their HOOK functions for extending functionality. In custom module we can able to create our custom HOOK to alter data from other modules.This is achieved by using the function drupal_alter().

Drupal 7 : Programmatically adding Fields in View with Example

By Default Drupal Views show the fields that are configured in UI. Based on our requirements we can able to add custom fields to view on rendering. This feature is achieved by using the HOOK hook_views_pre_view(). Using the object of $view we can call function “add_item()” this will add the fields to the View.

Drupal 7 & 8 : Alter system path with custom Paths with Example

In Drupal system defines some paths. For example “node/add/CONTENT-TYPE”. We can change system path in custom module. There is hook function “hook_menu_alter()”. This hook loads all menu items in our system. By changing the items path by our custom path so system work with new path. In this hook we can also unset system path by unsetting item path.

Drupal 8 : Programmatically sent Mail from system - Example

In Drupal 8 there is function service() from core is used to send Emails. This function returns a object that help to trigger mail from system by passing argument as “plugin.manager.mail”. Using this Object call mail() function. After initiate mail need to call hook_mail() for define the Mail subject, Body and From address.

Drupal 8 : Custom Form Validate and Submit in hook_form_alter() with Example

In Drupal 8 we can able to call custom validate and submit function for our need. This custom functions need to be defined in hook_form_alter(). Validate is defined as array parameter for #validate key of $form array. Similarly for submit is defined as array parameter for #submit on $form submit action.