Wednesday, 22 February 2012

How to use in drush in ubuntu

1- First set path in bashrc file
      #PATH Variables
      PATH=$PATH:/home/amit/drush(Drush path)
      export PATH

$ gedit .bashrc
$ source .bashrc
now we use drush in ubuntu
$drush dl drupal

Tuesday, 21 February 2012

How to install LAMP in ubuntu

Type the following commands in terminal of ubuntu:-
#sudo apt-get install apache2
#sudo apt-get install php5 libapache2-mod-php5
#sudo apt-get install mysql-server mysql-server
#sudo apt-get install phpmyadmin
#sudo apt-get install libapache2-mod-auth-mysql php5-mysql
#sudo /etc/init.d/apache2 restart
set password according to your choose
and check on broswer

Thursday, 26 January 2012

Conditional fields in Drupal 7

Have you ever had to create a conditional input field? For example, one field is a checkbox that reads "Do you have children?" and if the user selects "Yes", we want to show an additional input field that asks "How many?" (and if the user selects "No" the field disappears).
I ran into this in a recent project and, as usual, added some custom javascript using #after_build that did exactly that. I'm pretty sure this is a widespread practice.

The secret is to use the new "container" type to wrap our conditional elements and control their visibility through the #states attribute:
$form['haskids'] = array(
  '#type' => 'checkbox',
  '#title' => t('Do you have children?'),
 $form['kids_container'] = array(
  '#type' => 'container',
  '#states' => array(
    'invisible' => array(
      'input[name="haskids"]' => array('checked' => FALSE),    ),
$form['kids_container']['numkids'] = array(  '#type' => 'textfield',
  '#title' => t('How many?'),
Using #states, we defined an invisible state for the container,
 which is triggered when the value of the "checked" attribute of the 
input specified by the selector is FALSE. It might at first seem a 
little confusing to mix in jQuery selector in PHP, but this is just how 
Drupal rolls and manages to bind the javascript event automatically. If 
in dobut, simply replace name="haskids" with your field's "name" attribute! 

Thursday, 29 December 2011

What is AHAH in Drupal? How it works

AHAH in Drupal is a feature provided by the Forms API.
  • You write the form using the Drupal Forms API.
  • You specify what button activates the AHAH behavior.
  • You specify what part of the form's HTML is to be replaced by the callback
  • You write a callback that generates the replacement HTML
  • Drupal manages everything so that when the button or control is used, the callback gets called and the replacement of HTML is done 
The AHAH framework is fully integrated into Drupal 6 so all you need to do is hook into it using Drupals form API. Here's an example of how to make the form API to use AHAH.
['my_form_submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 1,
'#submit' => array('my_form_submit'),//none JS version
'#ahah' => array(
'event' => 'click',
'path' => 'mymodule/js',
'wrapper' => 'myform-wrapper',
'method' => 'replace',
'effect' => 'fade',
'progress' => array(
'type' => 'bar',
'message' => t('Loading...')
We're focusing on the #ahah array at the end of the form array, let me explain the various parameters one by one:

This is the type of event that must be perform on the $form item (in this example the Submit button) in order for the AHAH behaviour to be triggered. 
Possible values: 'click', 'blur', 'change' (Optional will default to click) 
Examples: user clicking a button (click) or user selecting a value in a drop down menu (change)

This is the menu item or URL that is called when the "event" has been triggered. Without this AHAH will not be triggered.In the above example you would need to have a coresponding menu item defined in your hook_menu like so:
<?phpfunction mymodule_menu() {
$items['mymodule/js'] = array(
'page callback' => 'mymodule_js',
'access arguments' => array('access mymodule js'),
'type' => MENU_CALLBACK,
* callback function for mymodule/js
* The return HTML will be outputted by AHAH
function mymodule_js() {
drupal_json(array('status' => TRUE, 'data' => "Hello Drupal World"));;

It's important the you use the drupal_json function so that Javascript can understand the returned values/HTML.
Alternatively you could use the AHAH helper module which can handle all the menu definitions for you.

This is the ID of the HTML element on the current page that should be updated with the returned HTML from our #ahah['path'] defined menu path.
In our example 'wrapper' => 'mymodule-wrapper' corresponds to <div id="mymodule-wrapper">.....</div> and this div would display the "Hello Drupal World" text returned by our mymodule_js() menu function when AHAH has been triggered.

This is how you want the HTML returned from our #ahah['path'] menu function to be attached to our #ahah['wrapper'] defined wrapper.
By default it with replace the HTML currently in the wrapper with the new HTML, but you can also have the follow:
'after' = Insert returned HTML after the wrapper element'append' = Append returned HTML to the inside of our wrapper element.
'before' = Insert returned HTML before our wrapper element.
'prepend' = Prepend returned HTML to the inside of our wrapper element.

This is the jQuery effect you want to apply to the wrapper element when it receives the new HTML from our menu function. 
Possible values: 'none' (default), 'fade', 'slide'.

This is the type of animation you want to display while the user is waiting for the AHAH menu function to response. It can either be a progress bar or a throbber icon and you can also add an optional message too.The #ahah['progress'] value should be an array of settings (see example above). Here are the full parameters:#ahah['progress']['type'] = Type of animation to display, bar or throbber
  #ahah['progress']['message'] = An optional message that should be displayed with the progress bar or throbber. You should wrap the text in the t().
#ahah['progress']['url'] = An optional URL to a menu item that determines how full the progress bar is.

How to integrate Apache Solr with Drupal 6 in windows or linux

I want to share my experience of integrating Apache Solr (Full text search and powerful than drupal core search) with Drupal 6.

Step 1: Download Apache Solr module from here, and
place it in your drupal contributed modules folder.

Step 2: Before enabling the module, we need to do some additional configurations.
Download the apachesolr php client library from here .
After extracting the files, place solrphpclient folder into apachesolr module folder.

Step 3: Now enable Apache Solr Framework and Apache Solr Search modules from admin/build/moules section.

Step4:  Now download Apache Solr from here. and extract the contents.

Step 5: Unpack the tar ball or zip file downloaded in step 3 outsite your drupal installation and outside web root.

Step 6:  Goto /apachesolr1.4.0/example/solr/conf and copy schema and solrconfig files to the same directory and rename them as schema.bak and solrconfig.bak

Step 7: Copy schema and solrconfig files from your drupal installation apachesolr module to above location and replace wih existing files.

Step 8: Now open your command prompt and browse to apachesolr1.4.0/example directory.

Step 9: Type belo command to start apachesolr service
               >> java -jar start.jar
Step 10: Test your solr server admin innterface by visiting http://localhost:8983/solr/admin/ . If you can able to see admin page then your solr is running and ready to use with drupal.

Step 11:  Its time to configure drupal search with apache solr. Please goto admin/settings/apachesolr/index and run cron to index the content using apache solr search engine.

Step 12: Now goto admin/settings/apachesolr click on advanced configuration and make apache solr as default search. Now go to admin/settings/apachesolr/enabled-filters and enable the sorting filtrers.

Step 13: Now goto blocks and enable the necessary apache solr related blocks.

Step 14: To enable facets please go to admin/settings/apachesolr/enabled-filters and enable filters. Now go to blocks and enable the facets filtering blocks where ever you want !!

Sunday, 25 December 2011

Using Hook Views Query Alter

Building a website I recently ran into an issue where I had HTML search facets interacting with Drupal views. The user would click on the facet and it would filter the view depending on the argument. I ended up implementing hook_views_query_alter. To make sure the values I wanted to filter on were in the view, I added the search facets into the view as fields. This automatically joins the necessary tables so that you don’t have to.
Implementing hook_views_query_alter requires two parameters, view and query, both are passed by reference. Since this hook is called for every view the first thing I did was check that I was altering the right query by adding an if statement that checks the view name. After that you're free to modify the query as you wish. In my example, I looped through the search facets and added them as where statements and arguments to the query.

function search_views_query_alter(&$view, &$query) {
  if($view->name == 'example_view_name'){
    foreach($parsed_url AS $key => $value){
      $query->where[0]['clauses'][] = 'profile_values_profile_' . $key . '.value IN ("%s")';
      $query->where[0]['args'][] = $value;

One of the search facets was a taxonomy filter which the user was allowed to multi select. In order to get the view to grab the correct values, I had to add join clauses to dynamically create term_node table aliases. This is done by adding a join clause to the table_queue and tables array elements within the query object. I was able to just copy the existing term_node table_queue and tables array elements because I only wanted to create different aliases. Then I incremented the existing term_node table count within the tables array. If you wanted to create a new table join dynamically, the same approach is used but the table_queue and tables definitions need to be created by hand.

foreach($parsed_url AS $key => $value){
  $vid = _search_get_vocabulary_id(str_replace('_', ' ', $key));
  $tid = _search_get_term_by_vocabulary($vid, $value);
  $table_term_node_join = $query->table_queue['term_node'];
  $query->table_queue['term_node_' . $count] = $table_term_node_join;
  $query->table_queue['term_node_' . $count]['alias'] = 'term_node_' . $count;
  $query->where[0]['args'][] = $tid->tid;
  $query->where[0]['clauses'][] .= 'term_node_' . $count . '.tid = %d';

The query table_queue and tables array elements looks like so:
Table Queue:

'table_queue' => array (
  'term_node' => array (
    'table' => 'term_node',
    'num' => 1,
    'alias' => 'term_node',
    'join' => views_join::__set_state(array(
      'definition' => array (
      'left_field' => 'vid',
      'field' => 'vid',
      'table' => 'term_node',
      'left_table' => 'node',
    'extra_type' => 'AND',
    'table' => 'term_node',
    'left_table' => 'node',
    'left_field' => 'vid',
    'field' => 'vid',
    'type' => 'LEFT',
    'adjusted' => true,


'tables' => array (
    'node' => array (
      'node' => array (
      'count' => 1,
      'alias' => 'node',
    'term_node' => array (
      'count' => 1,
      'alias' => 'term_node',

In my book this makes views more comfortable to use because it gives me more control over them. This along with a view preprocessor allows me to style and output pretty much anything I want within a view.

Wednesday, 7 December 2011

Embed Drupal Views Using PHP

When theming Drupal and wanting to output a view there are occasions where using a view display (e.g. a page, or a block - perhaps placed within a custom region ;-) ), or using Views Attach will not suffice.
Instead, you can embed a view using the following PHP snippet:
(NOTE: you'll need to have the core PHP input filter enabled if embedding in a node body)

= views_get_view('VIEWNAME');

or, if you need to use an argument with the view:
= array(ARGUMENTS);$view = views_get_view('VIEWNAME');
$view->preview('default', $args); 


  • replace VIEWNAME with your actual view name - e.g. 'my_drupal_posts'
  • replace ARGUMENTS with the argument(s) your view is expecting - e.g. this may be a node id
The PHP snippets above will output your view's 'default' display. However, you can output other displays from your view (if your view has multiple displays) - e.g. to output a view's first block display you'd modify the snippet by replacing the Views display id 'default' with 'block_1' and use:

= array(ARGUMENTS);$view = views_get_view('VIEWNAME');
$view->preview('block_1', $args);