Category Archives: CMS

Drush – The command line tool for Drupal development

In Drupal development, we spend quite a lot of time on module management.

  1. Browser: Go to the module page
  2. Browser: Copy the download link
  3. Shell: Go to the sites/all/modules directory
  4. Shell: Download the module using the wget command with the copied link
  5. Shell: Extract the module by the tar command
  6. Shell: Remove the extracted archive
  7. Browser: Login to the Drupal instance and go to the module page
  8. Browser: Enable the module

 

A typical Drupal website requires about twenty modules. That means you need to repeat the above tedious steps for twenty times. Besides, you have to move your focus between the browser and the shell prompt.
Continue reading Drush – The command line tool for Drupal development

Drupal 7 – Customize Ubercart invoice email template

You can find the Ubercart invoice email template files @ sites/all/modules/ubercart/uc_order/templates. You could copy and edit the uc-order–customer.tpl.php to fit your needs but you could not select it @ E-mail customer checkout notification > Email an order invoice in Rules. This is because you have to implement the hook_uc_invoice_templates() before the new template is selectable.
Continue reading Drupal 7 – Customize Ubercart invoice email template

Drupal 7 – Pass values from PHP to Javascript

During Drupal development, sometimes we may need to manipulate some server data in Javascript. In this case, we could create a custom module to retrieve the database data and pass it to browser such that we can it it in Javascript.

1. Implement the hook_init().

function <module-name>_init() {
  drupal_add_js(
    array(
      'eureka' => array( // we should use module name for best practice
        'data' => array(
          'Name' => 'ykyuen',
          'Blog' => 'Eureka!',
          'URL'  => 'https://eureka.ykyuen.info/',
        ),
      )
    ),
    'setting'
  );
}

Continue reading Drupal 7 – Pass values from PHP to Javascript

Run Drupal 7 in Nginx

After so many days we have talked about setting up Nginx, PHP-FPM, MariaDB and some PHP caching. We can now try to run a Drupal instance on them. Before we starts, let me listed out all the previous posts.

 

It’s time to start the Drupal installation.
Continue reading Run Drupal 7 in Nginx

Drupal 7 – Render Views Exposed Filter programmatically

Update at 2015-04-27: Another suggestion by Petu which could render the filter as a block programmatically.

Update at 2014-09-18: An simpler way to do that is to enable the Exposed form in block in the view settings and then render the block as suggested by plano.com.

The following piece of code render the Views Exposed Filter.

$view = views_get_view('<view name>');
$display_id = 'page';
$view->set_display($display_id);
$view->init_handlers();
$form_state = array(
  'view' => $view,
  'display' => $view->display_handler->display,
  'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
  'method' => 'get',
  'rerender' => TRUE,
  'no_redirect' => TRUE,
);
$form = drupal_build_form('views_exposed_form', $form_state);
print drupal_render($form);

 

Done =)

Reference:

Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 2

We talk about how to generate a taxonomy term selection list in the following post.
Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 1

So we continue to add the jQuery/Javascript code such that when the term is selected, the browser will open the corresponding term page.

The following piece of jQuery/Javascript is redirect you to the selected term page.
Continue reading Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 2