Create a batch Drupal 7


/**
 * Implements hook_form().
 */
function _demo_batch_form($node, &$form_state) {
  $form = array();
  
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'submit',
  );
  
  return $form;
}

/**
 * hook_form() submit handler.
 */
function _demo_batch_form_submit($node, &$form_state) {
  $batch = _demo_batch();
 
  batch_set($batch);
}

/**
 * Demo batch.
 * 
 * Alter the node title from node ID {$nid} {$count} times.
 */
function _demo_batch() {

  $nid = 150;
  $count = 500;
  $operations = array();
  

Use of external style sheets in Drupal 7

External style sheets can't be added in the themes .info file

In Drupal 7, drupal_add_css is used to add external style sheets. In this example, the minified Bootstrap's CSS is fetched.


/**
 * Implements template_preprocess_html().
 */
function subtheme_preprocess_html(&$variables) {
  drupal_add_css('https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', 
    array('type' => 'external'));
}

Also, externally hosted style sheets are never aggregated or compressed.

Create a custom commerce checkout pane


/**
 * @module: 
 * Create a custom checkout pane for Drupal Commerce.
 */

/**
 * Implements hook_commerce_checkout_pane_info()
 */
function MY_MODULE_pane_commerce_checkout_pane_info() {
  $panes = array();
  // Custom checkout pane.
  $panes['CUSTOM_MODULE_PANE_NAME'] = array(
    'title' =--> t('Shipping service'),
    'page' => 'shipping',
    'weight' => 11,
    'base' => 'CUSTOM_MODULE_PANE_NAME_pane',
    'fieldset' => TRUE,
  );
  return $panes;
}

/**
 * Implements base_settings_form().
 */

Remove all CSS files except current theme files

Function is placed in template.php.


/**
 * Implements hook_css_alter().
 */
function MYTHEME_css_alter(&$css) {
 
  dpm('-- Before unset --');
  dpm($css); 
 
  foreach ($css as $key => $value) {
    if ($value['group'] != CSS_THEME) {
     unset($css[$key]);
    }
  }

  dpm('-- After unset --');
  dpm($css);
   
}

CSS_THEME is a constant defined in common.inc and refers to the group of theme CSS files

Create a subtheme Drupal 7

This example show the basics to create a subtheme in Drupal 7.

First of all, create a new directory in the sites theme folder to add the custom theme.

Create the .info file, aside the mandatory name and core properties, and the recommended desription property, add the base theme property.

The custom theme can be activated on the /admin/appearance page.

Create extra fields on nodes

Use hook_field_extra_fields to use the new fields with the manage display function. The content of the new field is built in hook_node_view.

Change user password using Drush

drush user-password admin --password="admin"

drush upwd admin --password="admin"

IP address classes and private IP addresses

IP address classes

Class First octet decimal range
Class A 1 to 126
Class B 128 to 191
Class C 192 to 223

Private IP addresses

Class Address Range
A 10.0.0.0 to 10.255.255.255
B 172.16.0.0 to 172.31.255.255
C 192.168.0.0 to 192.168.255.255

Pages

Subscribe to Dribbit.eu RSS