Graham's Blog

Categories:

Remove "Split summary at cursor" button

function foo_form_alter(&$form, $form_state, $form_id) {
  if ($form['#id'] == 'node-form') {
    if (!empty($form['body_field'])) {
      $form['body_field']['teaser_js']['#type'] = 'hidden';
      $form['body_field']['teaser_include']['#type'] = 'hidden';
    }
  }
}

Credit Snipplr.com

Add items to cart with dynamically set attributes

You first create some attributes for a product that have no options and are set as text field, then add to cart with their attribute IDs set.

<?php
	uc_cart_add_item(95, 1, array('attributes' => array(3 => $form_state['values']['property_name'], 2 => $form_state['values']['property_nid'])));
?>

Form alter a text field to be readonly the ghetto way

<?php
 
$form['Association_Name']['#title'] = $form['field_association_name']['#title'];
		$form['Association_Name']['#value'] = "<label><strong>Association Name:</strong></label><br />" . $form['field_association_name'][0]['#default_value']['value'];
		$form['Association_Name']['#weight'] = $form['field_association_name']['#weight'];
		$form['field_association_name']['#access'] = 0;
 
?>

Get current path

$path = drupal_get_path_alias($_GET['q']);

Fix on change in IE8 for jquery (Stupid IE!)

$(function () {
    if ($.browser.msie) {
        $('input:radio').click(function () {
            this.blur();
            this.focus();
        });
    }
});

Search and replace within files with bash

find ~/httpdocs -maxdepth 1 -name \*.php -exec perl -pi -w -e "s/\<\/body\>/\<\?php\ include_once\('includes\/footer_inc\.php'\);\ \?\>\<\/body\>/g" {} \;

THANK YOU KYRA!!!

Drupal form Onfocus attribute

$form['search_theme_form']['#attributes'] = array('onfocus' => "if (this.value == 'Search My Site') {this.value = '';}" );

Make Ubercart Order Comment

This example makes an admin comment

uc_order_comment_save($order->order_id, 0, $str, 'admin');

Standard cron job for Drupal

Hourly cron job:

crontab -e
* 1 * * * /usr/bin/wget -O - -q -t 1 http://www.domain.com/cron.php

add WWW's to no WWW's

RewriteEngine on
 
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (<a href="http://example.com/" title="http://example.com/">http://example.com/</a>... will be redirected to <a href="http://www.example.com/" title="http://www.example.com/">http://www.example.com/</a>...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#