Drupal

Drupal 7 : Programatically Loading and Updating Commerce products with Example

We using Drupal Commerce to store and retrieve line Items. It treat product as separate entity. The product informations are able to load by its product ID, the product information we get as Object. Using the product object we can update the values of commerce product. The below Syntax and example shows how to load commerce product and update values programatically.

Drupal 8 : How to use MERGE(INSERT+UPDATE) query with Syntax and Example

MERGE is the short hand Drupal database statement used to perform both INSERT and UPDATE functionality in same code. It Will check whether record is already exits with given condition, yes then update based on condition otherwise insert a new record. The merge() is a function of Drupal 8 core class used for MERGING record based on condition records. Below is syntax and example of how to use MERGE statements in Drupal 8.

Initial Table be like:

Related Blogs:

Drupal 8 : How to use DELETE query with Syntax and Example

Using the object of core Drupal class we can perform database queries. Delete is the data deletion query used to remove data from Database based on conditions. The delete() is a function of Drupal 8 core class used for remove records. Below is syntax and example of how to use DELETE query in Drupal 8.

Before Delete Table be like:

EMPLOYEE_ID EMPLOYEE_NAME EMPLOYEE_AGE
CE 001 Mohan 20
CE 002 Dinesh 17
CE 003 Kumar 25

After Performing delete Query table records like:

Related Blogs:

Drupal 8 : How to use UPDATE query with Syntax and Example

UPDATE is the Data Manipulation Language(DML) query in Database management system. Using the object of core Drupal class we can perform database queries in Drupal 8. Update is the data modifying query used to change data in Database. The update() is a function of Drupal 8 core class used for update records. Below is syntax and example of how to use INSERT query in Drupal 8.

Before Update Record in Table be like:

EMPLOYEE_ID EMPLOYEE_NAME EMPLOYEE_AGE
CE 001 Mohan 20
CE 002 Dinesh 17
CE 003 Kumar 25

 

Related Blogs:

Drupal 8 : How to use SELECT query with Syntax and Example

Using the object of core Drupal class we can perform database queries. Select is the data retrieval query that has been done with help of select() of Drupal 8 core class. Below sample show how to use select query in Drupal 8.

Output:

EMPLOYEE_ID EMPLOYEE_NAME EMPLOYEE_AGE
CE 001 Mohan 20
CE 002 Dinesh 17
CE 003 Kumar 25

Related Blogs

Drupal 8 : How to use INSERT query with Syntax and Example

Insert is the Data Manipulation Language(DML) query in Database management system. Using the object of core Drupal class we can perform database queries in Drupal 8. Insert is the data saving query used to store data to Database. The insert() is a function of Drupal 8 core class used for insert records. Below is syntax and example of how to use INSERT query in Drupal 8.

Before Insert Table be like:

EMPLOYEE_ID EMPLOYEE_NAME EMPLOYEE_AGE
CE 001 Mohan 20
CE 002 Dinesh 17

 

After Performing Insert Query table records like:

Related Posts:

Drupal 7 : Accessing User Profile fields and changing programmatically with example

In Drupal 7 Profile2 module help to create user profiles. The Profile2 module handle each profiles as separate entity with set of Drupal fields. Similar to changing user account we can change profile values. Below example show how to access profile values and updating profile values.

Drupal 7 : Select list options by Taxonomy term depth(Parent Child) with source code

In Drupal by Taxonomy term list are arranged as parent child format. Similarly we can able to create List option in our custom form. Below is the source code to generate option array as Parent child hierarchy. List key is Term ID and display name is Taxonomy term hierarchy.

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 8 : Programmatically create File in server with sample code

In Drupal 8 we can able to programmatically create files in sites file system. By using function “file_save_data()” from Files module from core. This function accepts parameter of file content with optional parameter as destination and replacement type.

Drupal 7 : Programmatically render view(views_get_view()) with Exposed filters - Samplecode

In Drupal 7 we render view by calling the function views_get_view(), this function render returns view results. Normally we filter view result by specifying filters in view or exposed filters. For programmatically rendering view we need specify the exposed filter value in object of view.