Skip to main content

Posts

Showing posts from April, 2016

Drupal Behaviors: A Quick Introduction

If you’re adding JavaScript to your custom module it is very easy and tempting to simply add it like this: jQuery(document).ready(function($){   alert(‘hot dog flavored water’); }); Now this code works perfectly fine but what if your JavaScript needs to be executed on page load and after an AJAX request? Imagine you have a view that uses “Views Infinite Scroll” and you want add a CSS class to every result like this: jQuery(document).ready(function($){   $('.view-display-id-page .views-row').addClass('fancy-pants'); }); This will work for the results that are displayed initially but for all the results that are loaded by Infinite Scroll's AJAX call the class is not added. That’s where Drupal behaviors come in handy.  The behaviors will be executed on every request including AJAX requests, so let's do the equivalent of the code above but this time using this method: Drupal.behaviors.infiniteScrollAddClass = {   attach: function (context, settings) { ...

How to Configure Memcache on server

(1) Install Memcache module then configure according to memcache. (2) Download the module ( https://drupal.org/project/memcache ). (3) See the Documentation of how to configure memcache module on server ( https://drupal.org/node/1131458 ). ## REQUIREMENTS ## - PHP 5.1 or greater - Availability of a memcached daemon: http://memcached.org/ - One of the two PECL memcache packages: - http://pecl.php.net/package/memcache (recommended): - http://pecl.php.net/package/memcached ## INSTALLATION ## These are the broad steps you need to take in order to use this software. Order is important. 1. Install the memcached binaries on your server. See for instance: http://www.lullabot.com/articles/how_install_memcache_debian_etch 2. Install the PECL memcache extension for PHP. This must be version 2.2.1 or higher or you will experience errors. 3. Put your site into offline mode. 4. Download and install the memcache module. 5. If you have previously bee...

Most Importanct Drush Commands

Core drush commands: (core)  archive-dump (ard,    Backup your code, files, and database into a single      archive-backup, arb)  file.                                                    archive-restore       Expand a site archive into a Drupal web site.            (arr)                                                                          cache-clear (cc)      Clear a specific cache, or all drupal caches.            cache-get (cg)        Fetch a cached object and display it.               ...

Some Changes in drupal 7 and drupal 8

There are following changes in drupal7 and drupal8. 1. variable_set()/variable_get() are gone In Drupal 7, all variables are global, so accessing and saving them is done this way: // Load the site name out of configuration. $site_name = variable_get('site_name', 'Drupal'); // Change the site name to something else. variable_set('site_name', 'This is the dev site.'); In Drupal 8, configuration will only be lazy-loaded when needed. The above code would therefore change as follows: // Load the site name out of configuration. $config = config('core.site_information'); $site_name = $config->get('site_name'); // Change the site name to something else. $config->set('site_name', 'My Awesome Site'); $config->save(); 2. $_GET[‘q’] is gone The PHP super global key $_GET['q'] is 100% missing in Drupal 8, now you are forced to use the standard method current_path(). Drupal 7: function contact...