Drupal Installing composer drush through command line

Drupal Installing composer and drush through command line.

This article explains drupal installing composer and drush through command line on windows environment. Composer is dependency Management for PHP. Drush is a command-line tool for building and maintaining sites.

Installing composer and drush for drupal

Composer helps you declare, manage and install dependencies of PHP projects. Use Composer to manage dependencies in your php applications.

Composer requires PHP 5.3.2+ to run. A few sensitive php settings and compile flags are also required, but when using the installer you will be warned about any incompatibilities.

Installing Composer

Download the installer to the current directory
php -r “copy(‘https://getcomposer.org/installer’, ‘composer-setup.php’);”

Verify the installer SHA-384
php -r “if (hash_file(‘SHA384’, ‘composer-setup.php’) === ‘669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410’) { echo ‘Installer verified’; } else { echo ‘Installer corrupt’; unlink(‘composer-setup.php’); } echo PHP_EOL;”

Run the installer
php composer-setup.php

To install it to specific directory
php composer-setup.php –install-dir=bin

To install a specific version
php composer-setup.php –version=1.0.0-alpha8

Remove the installer
php -r “unlink(‘composer-setup.php’);”

Test the Installation
composer -v


composer and drush


Drush is a command-line tool for building and maintaining drupal sites. Drush provides additional functionality not available via the administrative interface. It is used install he base software, modules, and themes; updating software; performing database operations, including copying and querying; resetting passwords; and clearing the cache. Doing administrative tasks using Drush is typically faster and less tedious than performing the same tasks through the administrative interface.


Installing Drush

composer require drush/drush

To run Drush
vendor/bin/drush help


Use full links:




Get users who flagged a node

Get users who flagged a node

This article will explain how to get users who flagged a node in drupal. Drupal provides a contributed module named Flag module which is used to create unlimited arbitrary flags or bookmarks to flag content.

In one for the Drupal project we had a requirement to get users who flagged a node and display their details when ever that node is viewed in the browser.

To get users who flagged a node, here node can be any thing like blog post, user, content type etc… we need to invoke flog module in our custom module or block that has to display the users list.

Use below code to get all the users who had flagged a particular node.

Step 1 :  To get the node ID from URL

if (arg(0) == 'node') {
  $nid = arg(1);

Step 2 :  Using node ID get users who flagged a node.

$user_ids=array(); //User Array initialization 
$nid = 2; //node ID
  $flags = module_invoke('flag', 'get_content_flags', 'node', $nid);
  if (isset($flags)) {
    foreach ($flag as $uid => $data) {
       $user[] = $uid; //Adds user ids to the user array.

To get User pictures user below code

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $nid = $node->nid;
  $accounts = module_invoke('flag', 'get_content_flags', 'node', $nid);
  if (isset($accounts)) {
    foreach ($accounts as $uid => $data) {
      $account = user_load(array('uid' => $uid));
      print theme('user_picture', $account); //Substitute this with whatever you'd like to display from the user.

To read more about Drupal from here

Drupal get comments of node

Drupal get comments of node

In Drupal 7 you can use the below code to get all the comments of a node using node ID

$nid = 2; // node ID
    $comments = db_select('comment')
              ->fields('comment', array('name','subject'))
              ->condition('nid', $nid, '=')
    foreach($comments as $comment) {
        print your comments here

In Drupal 6 you can use the comment_render() ;