In Drupal theme provide the design for the pages and contents. We can use multiple themes for our website. Using the user role, permission and page URLs we can able to change the theme. This is the simple example of implementing theme per page by URL.
The CTools is the plugin that helps to achieve popup content in Drupal. Not only the content and pages we can render forms in CTools. The below is the example will demonstrate about create a form in CTools modal popup window.
The CTools module helps us to implement popup functionality in Drupal. Using CTools modal popup we can create Custom pages, forms, blocks into popups. The below example will demonstrate creating simple Modal popup page with sample code.
The Autocomplete field will suggest the information while user typing initial values. Inform text field fields we can able to change as autocomplete field instead of the normal text field. The below is the example text file into a autocomplete field in Drupal 6.
Normally content are created and managing is done using node form in Drupal. There is node create form and edit form help create and manage contents in Drupal sites. the hook function hook_form_node_form_alter() will help to achieve altering node forms to alter.
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.
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.
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.
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().
Using the Drupal core currentUser() function we can get logged in user details as Object. Using the object we can determine the user is logged in or not. The below is the sample code of checking whether the user is logged in or not.
In Drupal Form API we can able to add prefix and suffix for fields. There are two types of adding prefix and suffix. a. Adding to Form Field b. Adding to Form elements
The below example shows how to redirect a user after login. This example code will not be affecting the password reset functionality of Drupal core.
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.
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().
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.
In Drupal “Services” module help to create services for us. We can also able to create our own services in our custom modules. This can be achieved implementing hook_services(), this hook help to define our service type and service functionality.
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.
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.
In Drupal we can define custom validate, on validation able to set field errors. This error is set with help of FormStateInterface object by calling function “setErrorByName”. This functions need 2 arguments to set errors.
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.