Tag Archives: Drupal

Drupal 7 – Set a date fieldCondition in EntityFieldQuery

We can select nodes by conditions using EntityFieldQuery.
Drupal 7 – Get specific nodes using EntityFieldQuery

After I have installed the Date module, I could create a content type with a date field called field_expiry_date. When i setup this field, there are 3 date options in the field type.

  • Date
  • Date (ISO format)
  • Date (Unix timestamp)

Continue reading Drupal 7 – Set a date fieldCondition in EntityFieldQuery

Drupal 7 – Create a Datetime field in hook_schema() @ 2

Yesterday we talked about defining a datetime field for the table created by custom module.
Drupal 7 – Create a Datetime field in hook_schema() @ 1

As i have mentioned in the above post, the datetime field is no longer support by the Drupal Schema API. If you don’t want to use the datetime field, you can try to save the datetime in timestamp format and stored it in an int column.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 2

Drupal 7 – Create a Datetime field in hook_schema() @ 1

Next: Drupal 7 – Create a Datetime field in hook_schema() @ 1

If your custom module requires an additional table in the Drupal database, you have to create the .install file and define the schema inside it. In Drupal 7, the datetime field is no longer support by the Drupal Schema API. If you want to create a datetime field, you have to use the mysql_type or pgsql_type. Here is an example.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 1

Drupal 7 – Mutiliple selection list for taxonomy using Hierarchical Select

Taxonomy is a must have tool for grouping relevant content together. On the other hand, with the help of Views and exposed filter, user could easily list out the content with specific taxonomy.

But when a taxonomy has more than 1 levels, the filter option list may get too long and become less user friendly. In the past, i tried to make a multiple selection lists by applying some Javascript and jQuery on the exposed filter. It turns out that the result is quite bad.

Recently i found that there is a module which could turn the multiple levels taxonomy into multiple selection lists. It is called Hierarchical Select written by Wim Leers who is also the author of Drupal CDN module. Let’s try it now.
Continue reading Drupal 7 – Mutiliple selection list for taxonomy using Hierarchical Select

Drupal 7 – Create a URL which display the latest node of a specific content type

I want to create a URL which will redirect to the latest node of a specific content type so i write a custom module. In this example, the content type car is used.

latest_car.info

name = Latest car
description = Create a URL which will redirect to the latest car node.
package = Eureka;
version = 7.x-1.0
core = 7.x

Continue reading Drupal 7 – Create a URL which display the latest node of a specific content type

Drupal 7 – Set Query Strings in the path for form_state[‘redirect’]

Previously we talked about adding query strings for drupal_goto().
Drupal – Escape the Hex Characters in drupal_goto()

When the form is submitted, we can decide the redirect path in the form_submit() function.
Redirect to node/1 after form submission

function <form id>_submit($form, &$form_state) {
  $form_state['redirect'] = 'node/1'
}

 
Continue reading Drupal 7 – Set Query Strings in the path for form_state[‘redirect’]

Drupal 7 – Add the latest jQuery on your Drupal 7 without conflicts

A few months ago, i tried to add the latest jQuery to a Drupal 6 website. If you are still working on Drupal 6. Please refer to Drupal – Add Extra jQuery Library.

The approach we used in the above post does not work in Drupal 7 since drupal_set_html_head() has been renamed to drupal_add_html_head() and inline Javascript is no longer supported in this new version. So today i would like to show you another solution which works in Drupal 7.
Continue reading Drupal 7 – Add the latest jQuery on your Drupal 7 without conflicts

Drupal 7 – Order EntityFieldQuery by random using hook_query_TAG_alter()

The EntityFieldQuery does not support any method to select the entities by random. A simple workaround is using the query tag and implement the hook_query_TAG_alter().

Add addTag() in your EntityFieldQuery object.

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', '<node type>')
  ->propertyCondition('status', 1)
  ->addTag('random')
  ->range(0, 1);

Continue reading Drupal 7 – Order EntityFieldQuery by random using hook_query_TAG_alter()

Drupal 7 – Customize region template file for specific content type

We can add preprocess function for regions such that we can add customization before rendering the region template file(.tpl.php).
Drupal 7 – Check if the current loading page is the node view page of a specific content type

Sometimes we may even want edit the template file(.tpl.php) for specific content such as a content type node view. In Omega theme, there are different regions and by default they will use the following template files.

<drupal>/sites/all/themes/omega/omega/templates

  • region--branding.tpl.php
  • region--content.tpl.php
  • region--menu.tpl.php
  • region--sidebar_first.tpl.php
  • region--sidebar_second.tpl.php
  • region.tpl.php

Continue reading Drupal 7 – Customize region template file for specific content type

Drupal 7 – Check if the current loading page is the node view page of a specific content type

I try to preprocess the content region of the Omega theme for a specific content type. So i have to check the content type inside the <subtheme>_alpha_preprocess_region(&$vars) function so that the preprocess modification only applies to that content type. In that case, we could make use of the menu_get_object() provided by the Drupal API.
Continue reading Drupal 7 – Check if the current loading page is the node view page of a specific content type