Tuesday, August 8, 2017

Get all terms from the vocabulary

To get all terms from the specific vocabulary use below snippets

$vid = 'name_of_vocabulary';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
 $term_data[] = array(
  "id" => $term->tid,
  "name" => $term->name

Friday, July 28, 2017

Install Drush using composer for Drupal 8 in Windows 7 OS


Composer need to be available in your windows machine

Update composer with below package

composer require symfony/var-dumper:v2.7
composer remove phpdocumentor/reflection-docblock:3.1.1
composer remove drush/drush:8.x-dev

Note: If you still face an issue, read composer error message, it provides details about what is missing in your installation.
for example 

Problem 1
    - Installation request for drush/drush 8.x-dev -> satisfiable by drush/drush[8.x-dev].
    - drush/drush 8.x-dev requires phpdocumentor/reflection-docblock ^2.0 -> satisfiable by phpdocumentor/reflection-docblock[2.0.0, 2.0.0a1, 2.0.0a2, 2.0.0a3, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5] but these conflict with your requirements or minimum-stability.

Saturday, July 8, 2017

Install drupal console using composer

To install Drupal Console using composer for Drupal 8, use below command from command prompt

composer require drupal/console:~1.0 \
--prefer-dist \

Friday, June 20, 2014

Improve Performance in PHP based website

Some of the basics but essential for performance tuning to any PHP based website

  1. Reduce no of http requests in page.
  2. Index queries which takes too much time. Find expensive queries by activate MySQL slow query log. We can also easily identify which query not use index by specify additional parameter in my.conf reference.
  3. Use PHP function instead of MySQL function. i.e. CURDATE() function gives current date in MySQL use PHP Date function instead of that.
  4. Cache (very basic but it is worth to mention! ). i.e. APC, Memcache
  5. Browser cache is another way when we have less dynamic content.
  6. Minify JS and CSS to reduce document size. Document size mean total size of your HTML page.
If we take care above points we can get good performance for sure.

Wednesday, February 22, 2012

Hide format drop down from body

Drupal is such a nice CMS but some of the additional feature may gives us trouble for non technical users. The very common example is Text format drop down in body field. Most of the user try many ways to hide that details. Use following code to hide drop down from node add/edit form

Using hook_form_alter add following code in form alter.

$form['body']['und'][0]['format']['guidelines']['#access'] = FALSE;
$form['body']['und'][0]['format']['help']['#access'] =FALSE

Please share your thoughts if you have any other quick way to hide.

Wednesday, December 14, 2011

Log in as Another user or Admin User

While working with Drupal based project, many times we needs to check different menus with other users account.  Masquerade module is the best solution to handle such situation.

The Masquerade module is useful to those users who wants to temporarily switch to another user account. It also provide option to switch back to the original account.

We can use this module for Individual users as well as specific to  User Role

Steps to use Masquerade  module in Drupal 7
  1. Download  Masquerade module and place it to sites/all/modules folder.
  2. Install that module from Admin , Modules
  3. Set "Masquerade" block from Admin, Structure, Block.
  4. Set permission. We can configure "Masquerade" module in two ways
    1. User Level: 

      1. Go to Admin,  People 
      2. Edit any user profile. Specify usernames what we needs to switch from edited user account in comma separated.

    2. Role Level

      1. Go to Admin , People, Permission.
      2. Set following permissions to specific role

 After implement above settings when  user login following block will appear in page.

When we specify any other user in textbox and press Go button block appear as follows

I am sure that above information will helps you lot. Thank you very much for reading this blog.
Please share your comments regarding this Article.

Thursday, November 10, 2011

The page isn't redirecting properly - Drupal Multilanguage Problem

In Drupal, many of us face above type of error during multi-language configuration with global redirect module.
We can resolve this error by two ways
1. Disabled Global redirect
2. By Applying Patch in global redirect

Once to update any one of technique in your error solve...

Reference: http://drupal.org/node/1082362