Skip to main content

Drupal 7

Change Drupal 7 decimal field scale or precision

Submitted by system on

We wanted to change the MRP field 'field_per_item_cost' from DECIMAL (12,2) to DECIMAL (12,3).

 The following SQL Query will do the trick:  

ALTER TABLE field_data_field_per_item_cost MODIFY field_per_item_cost_value DECIMAL(12,3); 

ALTER TABLE field_revision_field_per_item_cost MODIFY field_per_item_cost_value DECIMAL(12,3); 

UPDATE field_config SET data = REPLACE(data, '"scale";s:1:"2";', '"scale";s:1:"3";') WHERE field_name = 'field_per_item_cost'; 

Update Drupal 7 text fields max length for fields having data

Submitted by system on
<?php
/*
* Utility to change the max length of a text field
*/
function change_text_field_max_length($field_name, $new_length) {
$field_table = 'field_data_' . $field_name;
$field_revision_table = 'field_revision_' . $field_name;
$field_column = $field_name . '_value';

// Alter value field length in fields table
db_query("ALTER TABLE `{$field_table}` CHANGE `{$field_column}` `{$field_column}` VARCHAR( {$new_length} )");
// Alter value field length in fields revision table

Fixing Issue: Fatal error: "Maximum execution time of 240 seconds exceeded"

Submitted by system on
Search for drupal_set_time_limit in Drupal directory and modify the line as below. Ensure that it is restored later once the required operation is over: For example: Modify the following line in locale.inc file in includes/locale.inc. <?php drupal_set_time_limit(240); ?> and set to 1800. -- Source https://www.drupal.org/node/2085515#comment-7845525

Displaying field values with formatting

Submitted by system on
Displaying data for any entity fields with formatting can be achieved with 2 simple drupal api. field_get_items: Returns the field items in the language they currently would be displayed. field_view_value: Returns a renderable array for a single field value. Example: <?php $status_field = field_get_items('node', $node, 'field_status'); print render(field_view_value('node', $node, 'field_status', $status_field[0])); ?> -- Source https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 https://api.drupal.org/api/drupal

Configuring Disqus for Drupal

Submitted by system on
Disqus is a networked community platform used by hundreds of thousands of sites all over the web. With Disqus, your website gains a feature-rich comment system complete with social network integration, advanced administration and moderation options, and other extensive community functions. Configuring Disqus for Drupal is pretty straightforward. Install the disqus module, enable viewing Disqus comments permissions for anonymous users.

Organic Groups Views Exposed Filter Selection

Submitted by amitsedai on
It becomes very frustrating when one had to try various options but not be able to create drop down list of groups for selection via an exposed filter option in a view. There is a very simple solution to it. In the Group Audience field settings, select "Render Views filters as select list" option under ADDITIONAL BEHAVIORS. This selection would make the Group Audience field selected as an exposed filter display drop down options of all the groups available.

Alter field title of content type to display description below the field title

Submitted by system on
This can be achieved using hook_node_view <?php function ji_custom_node_view($node, $view_mode, $langcode) { if($view_mode != 'full'){ return; } switch ($node->type) { case 'blood_donor_form': foreach ($node->content as $field_name => $field_options) { if(isset($field_options['#title']) && isset($field_options[0]['markup'])) { $node->content["$field_name"]['#title'] = $field_options['#title'] ."".$field_options[0]['mark