Skip to main content

PHP

Opcache with Drupal

Submitted by system on
OPcache is an opcode cache for PHP. It is bundled with PHP 5.5.0 and later. The following settings work really well with Drupal. For Ubunti 14.04 , these following file can be modified to incorporate the changes /etc/php5/apache2/php.ini
Configuration: opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

Get URL Parameters

Submitted by system on
There are multiple methods for getting current URL parameters. The following seem to work fine. filter_input — Gets a specific external variable by name and optionally filters it . Works on PHP 5 >= 5.2.0. The following code gets the districts from the url provided in the parameter field_district_ref_nid. The filter input converts the result into an array. <?php $districts = filter_input(INPUT_GET, 'field_district_ref_nid', FILTER_DEFAULT, FILTER_FORCE_ARRAY | FILTER_FORCE_ARRAY); dpm($districts); ?> -- Source http://php.net/manual/en/function.filter-input.php

Drupal l() and url() methods

Submitted by amitsedai on
Both l and url methods are handy to create urls for various entities. However, the variety of options available makes the usage exciting and complex. l(): Formats an internal or external URL link as an HTML anchor tag. Syntax: l($text, $path, array $options = array()) Creating an absolute URL using l(). The example below creates a node link. <?php l(t('New product'), 'node/123', array('absolute' => TRUE)); ?> Add the previous url or the current page url before going to the new page.

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

Get list options of a field

Submitted by system on
We may want to get the options available for a field in content type. This can be achieved using Field API. <?php $blood_group_field = field_info_field("field_blood_group"); $blood_groups = list_allowed_values($blood_group_field); ?> where "field_blood_group" is the field machine name.

Creating exportable field definitions in Drupal 7

Submitted by amitsedai on
There are times when we would want to create similar data structures across multiple drupal sites for common functionalities. Although this can be done using features but when the effort involves one time exercise and involves just few fields to be exported, using custom code for creating export definitions for importing in the other site can be a simpler alternative. If you want export a field definition, you can use the handy field_info_field and field_info_instance functions.

Batch API

Submitted by system on
Drupals internal batch API can be really helpful for handling large cumbersome processes on your web server. Rather than submitting a form and waiting for one of these processes to finish before reaching the next page, the batch API can be utilized to break the process down across multiple page loads. This not only cuts down on the server load, but will prevent the page from timing out. Progress bars will be displayed to the user while the process runs which will keep them informed of where they are at in the process.

Modify Integer field to Decimal

Submitted by amitsedai on
The purpose is to modify the integer field which captures temperature in decimal. A good way is to execute a hook_update_N() API in custom module which allows incremental updates when installing, or visiting update.php WARNING: Does not work. Its better to recreate field after copying data to another temp field.

Allow HTML markup in quicktabs

Submitted by amitsedai on
Quicktabs by default strips html tags in Quicktab title by default. To add additional markup of text changes, hook_quicktabs_alter() is not sufficient the quicktabs tabset needs to be overriden to allow html markup in titles. hook_quicktabs_alter() to modify title.