Skip to main content

Displaying Graph Using HighCharts

Submitted by amitsedai on
HighCharts is a charting library tool made freely available for non commercial usage. Drupal HighCharts 2.x has no other module dependency except that HighCharts library needs to be downloaded from here. There are a huge variety of options made available in HighCharts API which can be used for manipulation and for additional info. The example below is a Line Chart uses Drupal HighCharts version 2.x <?php /* Render Line Charts using Drupal Highcharts 2.x */ function jicustom_chart_render($chart_arr){ $options = new stdClass();

jQuery Mobile Page Load Issue

Submitted by rajat on
Sometimes when we visit a link, specially on mobile, there is a situation when we place a link and reaching a page clicking that link leads to a situation where the jQuery library is not loaded into the browser. This could affect conditional fields and other jQuery widgets. The solution is to add rel="external" to the link.
-- Source http://stackoverflow.com/questions/10389751/jquery-mobile-page-load-issue

Using Drush Alias

Submitted by amitsedai on
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

Submitted by amitsedai on
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

Submitted by amitsedai on
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']); }

Drupal Date Manipulation

Submitted by amitsedai on
An easier way of getting difference between dates is achieved using the DateObject provided by Drupal. <?php $now_date = date_now(); $last_donation_date = new DateObject($node->field_date[LANGUAGE_NONE][0]['value'], 'UTC'); // Get difference in days in positive if $now_date is greater than $last_donation_date $diff_days = $last_donation_date->difference($now_date, 'days', FALSE); ?> Print a Date Object in any format using date_format_date: <?php print date_format_date($date_object, 'custom', 'Y m d'); ?> -- Source http://drupalcontrib.org/api/drupal/contr

Get All Options of a CCK Select Field

Submitted by amitsedai on
If you have a CCK Select field and you would want to extract the various options available in that field via custom code, the following lines help you achieve that. <?php $field = field_info_field('field_name'); $allowed_values = list_allowed_values($field); ?> Get the field name of the field(Machine Name) and list all possible options.

Validating CCK Form Fields

Submitted by amitsedai on
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

Submitted by amitsedai on
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