Tag Archives: Drupal

Drupal 7 – Several ways to get current URL

There are a few ways to get the current URL in Drupal 7. First, we can get the $_GET[‘q’] by the current_path() function. But it will ignore the language prefix if you are working on a multilingual site.

Examples of current_path():

http://example.com/node/306
returns “node/306”
http://example.com/drupalfolder/node/306
returns “node/306” while base_path() returns “/drupalfolder/”
http://example.com/path/alias
returns internal path such as “node/306” as opposed to the path alias
http://example.com/en/path/alias
returns internal path such as “node/306” as opposed to the path alias and language prefix is ignored

Continue reading Drupal 7 – Several ways to get current URL

Drupal 7 – Select node by language using EntityFieldQuery

Here is an example to select entities by the current language in EntityFieldQuery.

// Get the current language
global $language;

// Setup the EntityFieldQuery
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', '<CONTENT TYPE>') // ex. article
  ->propertyCondition('status', 1) // published nodes
  ->propertyCondition('language', $language->language, '='); // filter by current language

// Execute the query
$result = $query->execute();

 

Done =)

Drupal 7 – Pathauto and Transliteration

Pathauto is the most common module which i think almost all Drupal websites use it to format the path alias. Sometime we want to use the node title as part of the path alias but if we are working on multilingual Drupal website, this may lead to non english URL.

So we have the Transliteration module to solve the problem. It takes Unicode text and tries to represent it in US-ASCII characters by attempting to transliterate the pronunciation expressed by the text in some other writing system to Roman letters. In addition, it also helps creating clean file name on file upload.

1. Download and install the Transliteration module.
Continue reading Drupal 7 – Pathauto and Transliteration

Drupal 7 – In-place editing using Edit module

The Edit module allows you to edit the node content directly on the node view page. It works with CKEditor and also it will be included in the Drupal 8 core. So see how it works in Drupal 7 first.

1. Drupal 7 >= 7.22 is required.

2. Download and install the CKEditor and Edit modules.

3. Grant the Access in-place editing to the relevant roles.
Continue reading Drupal 7 – In-place editing using Edit module

BeansTag – Official release

After almost 2 years, the BeansTag module finally get through the review process and it is not officially released! If you want to find a simple tool to add page title and meta tags on your Drupal 7 website, BeansTag may be a good option for you.

BeansTag is a page title, meta tag and meta description management tool. You could add the above attributes to any path alias and they would be shown in the webpage. It fully support any pages including views, panel pages as well as nodes.

BeansTag also support multiple language since the language prefix in the path alias is also included when rendering the BeansTag.

Continue reading BeansTag – Official release

Drupal 7 – Add reset button to Webform

The Drupal Webform does not have the reset button by default. If you want to have one, you can create custom module to alter the form.

function <module>_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form_id, 'webform_client_form_') === 0 || ($form_id=='user_register_form')) {
    $form['actions']['reset'] = array(
      '#type' => 'button',
      '#value' => t('Reset'),
      '#weight' => 100,
      '#validate' => array(),
      '#attributes' => array('onclick' => 'this.form.reset(); return false;'),
    );
  }
}

 

The above code will add the reset button to all Webform as well as the user registration form.

Done =)

Reference: Drupal Webform – ‘reset’ button

Drupal 7 – Render a view with contextual filter argument programmatically

Some days ago, i write a blog post about how to render a Drupal 7 block programmatically.
Drupal 7 – Render a Block programmatically

If the block is created by Views, there is a simpler solution provided by the Views API. And we can also pass the contextual filter argument too.

print views_embed_view(<view machine name>, <display id>, <arg 1>);

 

Done =)

Reference: Outputting a Drupal 7 View programmatically with Contextual Filters (arguments)

Drupal 7 – Increase the number of values per field

A long time ago, i have a post about hacking into the CCK module so we could have more options when settings the number of values per field in the field setting page.
Drupal – Increase Views Relationship Delta Limit

This is a dirty approach as mentioned by eosrei.

So in Drupal 7, we can do it by creating a custom module and alter the field_ui_field_edit_form. Let’s implement the following hook_form_FORM_ID_alter() in a custom module.
Continue reading Drupal 7 – Increase the number of values per field