Drupal

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.

Drupal 8 : Webform alter change fields labels, hiding fields, custom validate and submit with example

In Drupal we can alter a form using the HOOK, hook_form_alter(). Webforms are used to create forms in interfaces. We can alter webform using hook_form_alter to change field types, label and custom validate or submit for our purposes. The below example will show editing the webform fields and adding custom validate.

Drupal 8 : Setting up Private file system (Simple 5 steps)

In Drupal 7 we can directly configure the Public and Private file at "/admin/config/media/file-system". But in Drupal 8 we cannot directly configure the private file system. To configure Private file system we need to specify the path in our "settings.php". The below steps help to configure Private file system for your Drupal 8.

Drupal 8 : Creating Directory/Folder using file_prepare_directory() and writing files

In Drupal we can able to store files. To save Folder/Directory need to be exist otherwise system through error as Directory not exist. The below sample code help to create Directory/Folder to copy a file. The function "file_prepare_directory()" checks directory exist or not, If exist copying a file otherwise create a directory and copying the file.

Drupal 7 : Entity Object(entity_load()) vs Entity Wrappered Object(entity_metadata_wrapper()):

In Drupal Node, User, Taxonomy, Files,.. are consider as entity. We can load the Entity information by it ID. There are two types of Entity load mechanisms, a). Entity Object(entity_load()) b). Entity Wrappered Object(entity_metadata_wrapper())

Drupal : Programatically Accessing Entity information - entity_get_info()

Entity is a object or instance of a base or extended class. Each entity have their own properties. The entity_get_info() is a function used for access entity information. Below is the sample code which show how to access the Entity information with entity ID.

Drupal : Loading revision of any Entity with example

In Drupal Node, User, Taxonomy, Files,.. are consider as entity. The combination of Entity type and Id is act as unique value. We can able to load each Entity as Object by using its unique id. For each update entity maintain a revision with an ID. Below is the example show how to load the revision information of a entity.

Drupal : Programatically update a Entity with Revision

In Drupal 7 and 8 we can able to update Entities values. By default it not creating revisions for update. To Ensure revision for or changes we need to add a "revision" parameter to the Object of Entity. Below is the syntax and example of programatically updating entity with revisions.codeexpertz