Tag Archives: Drupal

Drupal 7 – Add validation on your Drush command

Previously:

 

We could add validation to our drush command. What we need to do is to add the validation function. Let’s once again update our eureka_drush.drush.inc. Continue reading Drupal 7 – Add validation on your Drush command

Drupal 7 – Setup Bootstrap 3 Theme with Gulp for LESS compilation

Got a new responsive site freelance and i would like to try Bootstrap 3 theme in Drupal 7. A little bit confused at the very beginning because the theme has a lot of features and bug fixes ongoing. So the documentation is a bit lacking and i have to make some trials and errors before knowing what to do.

Some Drupal developers may also have problem on compiling LESS. So here i include a gulp script and some NodeJS packages to help.

Assume you have setup the Drupal 7.

1. Download the Bootstrap 3 Drupal theme. The current stable version is 7.x-3.0 which is a bit old and only works with Bootstrap 3.0.x. I am going to use 7.x-3.1 which supports the latest Bootstrap version (v3.3.2 at the moment i write this post). The 7.x-3.1 is still in beta (7.x-3.1-beta2). You could download it from the releases listing page.

2. Extract the Bootstrap 3 base theme to the sites/all/themes folder. You would found the starterkits folder containing the subthemes. as follow. Continue reading Drupal 7 – Setup Bootstrap 3 Theme with Gulp for LESS compilation

Drupal 7 – Write a Drush command which takes arguments input

Previously:

 

So it would be more useful if our drush command could take input arguments. Let’s modify the eureka_drush.drush.inc a bit.

eureka_drush.drush.inc

<?php

/**
 * Implementation of hook_drush_command().
 */
function eureka_drush_drush_command() {
  $items = array();
  
  $items['say-hello'] = array(
    'description' => 'Say Hello to someone',
    'arguments' => array(
      'whom' => 'Someone you want to say hello to. Defaults to "Kit".',
    ),
    'drupal dependencies' => array('eureka_drush'),
  );
  
  return $items;
} 

/**
 * Callback function for say-hello.
 * The function name is drush_<module_name>_<command_in_underscore>
 */
function drush_eureka_drush_say_hello($whom = "Kit") {
  $msg = 'Hello ' . $whom;
  drush_print("\n" . $msg . "\n");
}

Continue reading Drupal 7 – Write a Drush command which takes arguments input

Drupal 7 – Write your first Hello World Drush command

1. Create a new custom module. In this example, the module name is eureka_drush.

2. Create the eureka_drush.info.
eureka_drush.info

name = Eureka Drush
description = Custom drush command example.
core = 7.x
package = Eureka

 

3. Create the eureka_drush.module. Even if you do not have any implementation, leave it with just the PHP open tag.
eureka_drush.module

<?php

Continue reading Drupal 7 – Write your first Hello World Drush command

Drupal 7 – Get path alias by Node ID or Term ID

We did talk about using drupal_lookup_path() to get path alias.

The above function is still working in Drupal 7. We could also use the url() to get the path alias url as well.

// Get the node id path alias
url('node/' . $tid);

// Get the term id path alias
url('taxonomy/term/' . $tid);

 

Done =)

Reference:

Drupal 7 – Check add or edit in node form alter

If we want to alter a node form of a specific content type using hook_form_alter(), we may want to know whether the form is for node creation or edit. In this case, we can add a checking as follow:

function <module>_form_<content-type>_node_form_alter(&$form, &$form_state, $form_id) {
  $node = $form_state['node'];
  
  if (isset($node ->nid)) {
    // Node edit
  } else {
    // Node add
  }
}

 

Done =)

Drupal 7 – Avoid HTML tags stripped by CKEditor

Since version 4.1, CKEditor introduced the Advanced Content Filter(ACF) which limits some HTML tags so as to match the editor configuration in the best possible way. But that’s really annoying to me.

In order to disable the ACF, goes to @admin/config/content/ckeditor.
drupal7-ckeditor-disable-acf-1
 

Select the profile and goes to Advanced Options. Add the following Custom JavaScript configuration.

  • config.allowedContent=true;

drupal7-ckeditor-disable-acf-2
Continue reading Drupal 7 – Avoid HTML tags stripped by CKEditor

Drupal 7 – Alter the module execution order

Sometimes you may have 2 different modules implementing hook_form_alter() on the same form. In that case, the order of the module execution would follow the alphabetic order of the module name. If you want to alter the execution order, you could either update the system table in database or install the Modules Weight module.

1. Download and install the Modules Weight.
drupal7-module-execution-order-1
 

2. Go to admin/config/system/modules-weight to adjust the module weight.
drupal7-module-execution-order-2
 

Done =)

Reference: