Skip to main content

Drupal API

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.

Display node form fieldset using Form State API

Submitted by amitsedai on
Display a group fieldset using form state api. <?php /** * Display group group_name if control field field_control_name has value 2 */ function ji_custom_field_group_build_pre_render_alter(&$element) { if(isset($element['group_name'])){ $element['group_name']['#states'] = array( 'visible' => array( ':input[name="field_control_name[und]"]' => array('value' => 2), ), ); } } ?> -- Links: http://api.drupalhelp.net/api/field_group/field_group.module/function/field_group_build_pre_render/7 http://timonweb.com/programmatically-hiding-a-fieldgroup

Change the text of Apply Button on views Exposed form

Submitted by amitsedai on
The following snippet changes the views exposed form Apply Button to Search Jobs. Make the changes in template.php file of the currently enabled default theme. Clear cache to see it work.(Clear class registry cache to be precise.) <?php function YOUR_THEME_NAME_preprocess_views_exposed_form(&$vars, $hook){ // only alter the required form based on id // drupal_set_message(t("form id: ".$vars['form']['#id']), 'status', FALSE); if ($vars['form']['#id'] == 'views-exposed-form-search-openings-page') { // Change the text on the submit button

How to get the current node object

Submitted by amitsedai on
For Drupal6 , it is recommended to use menu_get_object() <?php $node = menu_get_object(); $story = $node->type == 'story'; ?> However in Drupal 7, node_load() also caches the current node object and in many cases, node_load() returns an object faster than menu_get_object() -- http://www.thecarneyeffect.co.uk/menugetobject-vs-nodeload-when-getting-node-object-drupal-7 https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_get_object/7

Using Entity Metadata Wrapper

Submitted by amitsedai on
The Entity API provides wrapper classes you may use to make dealing with the values of an entities properties and fields easier. Wrappers make it easier to get and set the values of fields and properties as well as to programmatically retrieve additional information about these elements and iterate over lists of values in a consistent manner. This implies that one need not worry about fetching a node property in the format: $node->field_name['und'][0]['value']

Using State API in Drupal Forms (Custom Conditional Fields)

Submitted by amitsedai on
The following is a snippet on how to enable fields to appear and/or disappear based on the state of other fields. <?php /** * Modifications for including State API functionalities. The idea is to hide the fields field_referme_industry * and field_referme_major_skills, based on the value of another field. * The functionality can be implemented during the after_build phase */ function jc_form_alter(&$form, &$form_state, $form_id) { //drupal_set_message("Form Id is: $form_id "); if($form_id == 'referme_node_form') {