Thursday, February 27, 2014

Alter single select box or multiselect box to radio buttons/checkboxes in exposed filters views

You can download "Better Exposed Filters" module to convert single select or multi select boxes to radio button or check boxes.

1. Go to "Advanced" section in views.

2. Check for "Exposed form" section in advanced.

3. There will be "Exposed form style" in Exposed form section.

4. Select "Better Exposed Filters" as exposed form style.

5. Add the checkboxes or radio buttons to the desired fields.

6. You are all done :).

What is contextual filter

Contextual filters work similarly to regular filters, but there is one important difference. Instead of setting a filter value manually, the value is fetched from variables sent programmatically to the view

The classic example of how contextual filter values are provided to views is by the view path. If a view has the path example.com/my-view, the URL example.com/my-view/story/22 will call the view along with two values for contextual filters (in this casestory and 22). But there are more ways of providing contextual filter values

Alter view query output

Using the hook_views_query_alter(&$view, &$query)  you can alter the query output from the views.
Put a print_r for $query & make the necessary changes to the $query array to alter the query
Use $view to get what the view name is

Add a node programatically into database in Drupal 7

 $node = new stdClass();
 $node->title = "title"
 $node->type = "node_type_name";
 $node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
 $node->uid = $uid;
 $node->status = 1;
 $node->promote = 0; //(1 or 0): promoted to front page
 $node->comment = 1; // 0 = comments disabled, 1 = read only, 2 = read/write
 $node->created = strtotime("now");
 $node->changed = strtotime("now");
 $node->moderate = 0;
 $node->sticky = 0;
 $node->tnid = 0;
 $node->revision = 1;
 $node->translate = 0;
  // add CCK field data
 $node->field_enrollment_id[$node->language][0]['value'] = '111';
 $node->field_enrolled_on[$node->language][0]['value'] = strtotime("now");
 $node->field_enrollment_status[$node->language][0]['value'] = 'ns';        
 $node->field_user_id[$node->language][0]['uid'] = $uid;
 $node->field_class_id[$node->language][0]['nid'] = $nid;

 $node = node_submit($node); // Prepare node for saving
 node_save($node);