Recent Blogz

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())