Using Drush Alias

drush aliases allow you to run a drush commands on your local server but actually execute the command on a remote server.

One can create aliases in a folder that drush recognizes, mostly inside the .drush folder for Linux Based Systems. For a mysite example, we can create a file called as mysite.aliases.drushrc.php inside the .drush folder (Or any folder which Drush goes through before executing). All aliases in a site can also be combined in a single file called as aliases.drushrc.php

Example data that can be added to mysite.aliases.drushrc.php

<?php

Drupal Custom Flag Operations

Technologies: 

Create a flag link for a user:

<?php
print flag_create_link('user_flagname', $user_uid);
?>

Get Flag of a Type and see if it is flagged for a node and not the number of times it got flagged.

<?php
$flag
= flag_get_flag('bookmarks') or die('no "bookmarks" flag defined');
if (
$flag->is_flagged($node->nid)) {
  print
"This node is bookmarked!";
}
print
"The number of people who voted for this proposal:";
print
$flag->get_count($node->nid);  //
?>

Flagging or Unflagging an item:
You use the $flag->flag() method to either flag or unflag an item. Example:

<?php

How to Modify Output of a View

Using views_pre_render hook one can alter the output of a view

<?php
/**
* Implements hook_views_pre_render().
*/
function jicustom_views_pre_render(&$view) {
if($view->name=='stock_report'){
$results = $view->result;
foreach ($results as $key => $result) {
$collection_name = $result->field_collection_item_field_name;
if($collection_name == 'field_transaction_items_outgoing'){
//Modify output
$results[$key]->field_field_trans_item_quantity[0]['rendered']['#markup'] = -($result->field_field_trans_item_quantity[0]['raw']['value']);
}

Validating CCK Form Fields

Technologies: 

Custom validations with form error set on CCK may require custom coding. This is one such exercise for both Drupal 6 and Drupal 7.

Drupal 6

<?php
/**
* Validations for Employee Leave
*/

function custom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if (
$op == 'validate' && $node->type == 'lms') {
   
$start_date =$node->field_lms_start_date[0]['value'];
   
$end_date =$node->field_lms_end_date[0]['value'];
    if(
$start_date > $end_date){
     
form_set_error('field_lms_start_date', 'Start Date of Leave Should be less than End Date of Leave');
    }
  }
}
?>

Site Benchmarking and Performance Improvement

Improving Site Performance:
1. Disable all caching in the site and do benchmark for anon user
2. Benchmark for auth user for a particular page
3. Check logs to see if any notice or error is happening in the site. Solve the issue and notice BM
4. Disable unwanted modules if any and do another benchmark. Note the diff.
5. Modify or update apache or mysql setting minor if any to see noticiable change in benchmark
6. Optimize PHP and see if noticeable difference occurs
7. Install Devel and check queries and page rendering times

Programmatically creating/deleting/modifying field-collection

Enough Said , visit the link: http://rajanmayekar.com/blog/programmatically-creating-deleting-modifyin...

One change wrt to deleting Field Collections is as follows:

<?php
$node
= node_load($node_id);
$field_collection_item_value = array();
foreach (
$node->field_collection_field[LANGUAGE_NONE] as $key => $value) {
   
$field_collection_item_value[] = $value['value'];
}
entity_delete_multiple('field_collection_item', array($field_collection_item_value));
?>

Using Git

Technologies: 

Version control of code files is important. Also important is to ensure that it is accessible throughout and also to the community from which we gain. I tried creating an account in GitHub, create and fork a repository and add files via commandline using git in Github.

Setting Up Git: