Saturday, August 19, 2017

To create new user from Drush command

To create new user using Drush use below command from Drush

drush user-create admin --mail=""  --password="admin"
Admin is the username
mail is the email address
and Password  , offcourse

Remove all contents from Drupal 8

To remove all contents, taxonomies, users and other content element. I would recommend to use delete_all module. Available in Drupal 7 and Drupal 8

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.