example

Drupal 7: PopUp By Ctools Automodal Module

  • Ctools Automodal will help you to create popup in your site. It is an easiest way to create a popup without any burden. To Create a popup form please follow the below instruction:-

  • Download and install the ctools Automodal(module) in your drupal instance.

    • Description : By using this module You can create your own custom form in popup.

Drupal 7: Programatically place a Commerce Orders with sample code

In Drupal 7 using the core functions of commerce, we can place orders programmatically. Using the function "commerce_product_line_item_new()" and "commerce_line_item_save()" we can add item to cart. The function "commerce_order_save()" will place all line items into order. The below is the sample code which demonstrates.

Drupal 7: Check given user Cart have items or not

We will add the product to the cart to checkout. The below is the code which used to check current user cart have the product or not. The function "commerce_line_items_quantity()" will returns the total quantity and "commerce_line_items_total()" will return cart total. These functions are taking the order line item array. This code will return an array of product that user have been added to his/her cart.

Drupal 7: Programatically Delete a Commerece order

The function commerce_cart_order_load() help to load the current user cart details. Using the cart order object details we can able to unset or empty the commerce cart of that user. The function commerce_cart_order_empty() help to achieve this. The below sample code demonstrate how to delete cart of a user.

Drupal 7: Programatically Loading commerece cart item of a user with samplecode

In Drupal commerce, cart items are handled as Entity. The cart items are referenced to the particular user id. Using user id we can able to load cart details that are currently added by the user. The function "commerce_cart_order_load()" takes user id as argument to load the cart details. The below example shows how to load cart details of the current user.

Drupal 7: Programatically update commerec Line Item with example

In programmatically we can able to alter commerce line items. The line items are kept as an entity in Drupal commerce system. Using the function "commerce_line_item_load()" we load line item as the object and able to access line item properties. The function commerce_line_item_save() will help to update the line item.

Drupal 7: Programatically Create Pagination with Example

The function theme() will help to create pagination programmatically in Drupal. While passing the argument "pager" to a theme() with the additional parameter for construct pager will return the pager. The below syntax and example demonstrate how to implement pager in Drupal 7.

Drupal 7 : Programatically Render Table - theme() Example

In Drupal we can able to create a Renderable table from array. This is achieved using function theme(). The theme function accepts Table header, row and attributes for table as associated array. The below syntax and example demonstrate build a table with Array.
Sl NoNameCountry
1MohanIndia
2DineshRussia
3SwathyAmerica
4GayathriEngland

Drupal 8: Enabling/Disabling Theme Debugging

Theme debugging will help on developing our Drupal 8 site. It will suggest the TWIG file that associate for DOM structure to change. This information is appended to command in HTML that Drupal renders. We can access this information in inspecting the HTML or on developer window. When debugging is enabled the markup of each Twig template is surrounded by HTML comments that, contain theming information, such as template file name suggestions.

Drupal 7 user_access() : Field level permission for create, edit, delete values

In Drupal we can specify the user role wise permission for access specific fields value create, edit and delete. This can be achieved by calling the fuction "user_access()" from user core module. This function accepts permission string and user object to check. The function return boolean value TRUE is user has permission else FALSE. Below is the syntax and sample code to use user_access() function.

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 8 : Programatically Enabling/Disabling Javascript Local storage for Drupal 8 Forms

Using the help of JavaScript we can able to store the values at browser(local storage). In Drupal 8 core "form.js" file help to maintain form local storage. This can be achieved by sitting boolean value to form key 'data-user-info-from-browser'. The below sample code show how to form variable to save in local storage.

Drupal 7 : Hiding Form Field groups with samplecode

For Drupal forms we can add Field Groups. These field groups are commonly HTML element, Div, HTML5, Fieldset, Vertical tabs group, Vertical tab, Horizontal tabs group, Horizontal tab, Multipage group, Multipage, Accordion group, Accordion item, Multiple fields container, Multiple fields table and Multiple fields as label-value. We can able to hide Field Groups in Form alter by different methods. Below are some types to hide the Field Groups.