Drupal 8 formatPlural(): Formatting count sentances with Singulars and Plural

In English grammar, there is importance to display words with proper nouns. The Singular and Plural will help to display sentences with numeric count components. Singular means only one. Plural means more than one. In Drupal 8 we can format both singular and plural values by formatPlural() function of Transulation Modules.

Drupal 8: Creating Hook Alters programatically with Example

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.

Drupal 7: Programmatically updating rules with example

Rules are used for trigger any action based on some condition pass. The contribute module Rule is used to achieve this features. We can able to programatically create and update rule action and conditons. The function rules_config_load() helps to load rule object by its name. The rule object will return attributes of particular rule. Using the object of rule we can able to edit its values.

Drupal 7: Commerce convert decimal to currency

In Drupal commerce will help to convert any numbers into a proper currency format. The function commerce_currency_format() helps to convert decimal numbers to particular country formatted currency. This function will accept a decimal number and country currency code for change given number into currency.

Drupal 7: Database Aggregate functions (SUM, MIN, MAX, COUNT, AVG,..)

The MySQL database query supports aggregate functions to retrieve values from the database. In our custom query, we can able to add aggregate queries. The function addExpression() takes object of database query to aggregate results in db_select(). The below example will demonstrate the usage of aggregate functions.

Drupal 7: Database query with MySQL Date functions

The MySQL is the database which stores any type of data in Database. Using the MySQL we can able to store date-related fields. The MySQL will support Date functions to retrieve and format database date field values. In Drupal also we can able to add date functions in our queries with help of where() function in the database object. The below is the syntax and example of usage of the where() function.

Drupal 7: Making Drupal block is no-cachable:

Drupal system makes blocks is cachable to speed render. The block cache is stored in Drupal core database block_cache table. By altering or change information of block as non-cachable. This is achieved by passing cache as "DRUPAL_NO_CACHE" in hook_block_info() for custom block and hook_block_info_alter() in existing block.

Drupal 7: Render/Display field value from entity object

In Drupal, each and every entity will different fields. These Fields are stored as the seprate table in Drupal system. Based on the field type(Text field, Body field, Integer, File upload field, entity reference field) the render display format can change. While rendering field value in our custom code need to concentrate on the field display format. The function drupal_render() with field_view_field() we can output formated values.

Drupal 7: Formating Date time (Changing Date based on timezone)

The Drupal will support different type timezone to process date related data. But actual data are stored in Unix time stamp format of UTC in the database. The Drupal default core system will process dates as configured in system configuration. While we accessing database date values we need to format to particular timezone date.

Drupal 7: Programatically adding new Commerce Product

In Drupal commerce, we can able to add new Commerce Products programmatically using the commerce_product_new() function. This will create an object of Commerce product, Using the object we can able to set their attributes for the product. The below is the example and syntax for creating the commerce product.

Drupal 7: Updating Administrator password programatically

There are several chances by accident we will forget administrator password for the Administrator. The newer version of Drupal core comes with the salt algorithm to encrypt the password. To update the new password we need to encrypt them before an update. The below is the example and syntax for update password. Add the below code in index.php above menu_active_handler().

Drupal 7 : Loading Order Details from LineItem ID

The Line Items in Drupal commerce used to refer the product in Order. Using the Line Item id we can able to load order details. The function commerce_line_item_load() will contains respective order ID of the order. We can able to get the order details from order ID using the function commerce_order_load().

Drupal 7: Programmatically update Commerce Line Item

In Drupal Commerce is an entity reference to the order during order creation. The line item will refer the product in the order. We can able to programmatically update the line item using the function "entity_metadata_wrapper()". The below example will show how to update the line items programmatically.