Drupal 7

Drupal Features Update and Revert

Features Update: Update a feature module on your site. This updates the feature module in the site if the components are overriden

drush fu <feature-module-name>

Features Revert: Revert a feature module on your site. Reverts the basic configuration in the module onto the site removing any custom configurations made at the database end.

drush fr <feature-module-name>

Custom Template files for Drupal CCK Forms

To render a Drupal CCK form in a template file, add the following lines in the currently enabled theme. Assuming the enabled theme to be footheme

For a cck form called external_exam, the theme function can be used to provide a template file called external_exam_form.tpl.php under templates directory.

<?php
function footheme_theme() {
  return array(
   
'external_exam_node_form' => array(
     
'arguments' => array('form' => NULL),
     
'template' => 'templates/external_exam_form',
     
'render element' => 'form'
   
),
  );
}
?>

Rendering a CCK field programmatically

Sometimes we need to render a field when we have a node object containing field values.

field_view_value is a Drupal API that allows us to render any field. Example: Display the Invoice Description Field in a Node Object. The display would take care of any input filter that is applied in the field

<?php
$invoice_description
= field_get_items('node', $node, 'field_invoice_description');
print
render(field_view_value('node', $node, 'field_invoice_description',$invoice_description[0]));
?>

The other way to display the label and data completely rendered by Drupal.

<?php

Memcache For Drupal in Ubuntu 13.04

Installation and Configuration of Memcached Daemon and PECL Memcache in Ubuntu for Drupal 7

Steps:

1. Install memcached in the server

sudo apt-get install memcached libmemcached-tools
sudo apt-get install php5-dev php-pear make
sudo pecl install memcache

Latest dev Version of Memcache can be installed via.

# If you haven't already installed PECL memcache
pecl install memcache-beta
# If you wish to "upgrade" to a beta release
pecl upgrade memcache-beta

2. Add memcache.ini in PHP conf.d directory

Displaying Graph Using HighCharts

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

Technologies: 

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

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']);
}

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));
?>