Drupal 7 disable submit button

Here’s how to disable the submit and preview buttons in a Drupal module.

$form[‘actions’][‘submit’][‘#disabled’] = TRUE;
$form[‘actions’][‘preview’][‘#disabled’] = TRUE;

Reference:
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#actions

Advertisements
Tagged with:
Posted in drupal

rsync

Today I was sending a large number of files to my server.

With rsync I was getting ‘broken pipe’ errors after a few hours of syncing files. Not nice.

I realised I don’t need to rsync the files that are already at the remote location … so with the help of this tip I removed files older than a certain date.

http://stackoverflow.com/questions/3676810/bash-delete-based-on-file-date-stamp

So now my rsync is looping though a smaller amount of files.

Posted in bash

Using Drupal 7 commerce_multicurrency with manual currency conversion

This is a note on how to implement the Drupal commerce_multicurrency module.

This recipe is for a site with two currencies, with manual currency conversion: we are going to manually add our prices in both currencies rather than using the European Central Bank conversion provided by commerce_multicurrency.

Users to the site may select which currency they wish to pay with, like this.

This slideshow requires JavaScript.

In my case, the default currency is GBP (British Pounds Sterling) and the additional currency is EUR (Euro).

Start with Drupal Commerce and its dependencies downloaded.

drush dl commerce
drush dl entity
drush dl rules
drush dl addressfield
drush dl views
drush dl ctools

I have enabled all of the commerce modules, and the dependencies as prompted.

Download and enable commerce_multicurrency.

admin/commerce/config/currency/settings

Enable the required currencies.
I enabled EUR and GBP, removed USD.
I set GBP as default.

In my case I want to have manual, not automatic, currency conversion.

Commerce Multicurrency provides a Currency Handling tab.

admin/commerce/config/currency/handling

I enabled a dedicated price field for Euro only.

(In my case the default price will be in British Pounds – I don’t need to enable a field to hold GBP prices – the default price field is enough).

Go to: admin/commerce/products/types
manage display so that the foreign currency field is hidden on the teaser and

Set up some products with product displays

Store > Products > Add

In Drupal Commerce, products do not display on the site automatically.

Add a content type called Product display. Add a Product Reference field to the content type.

On the manage display tab, hide the foreign currency field: we only want one field for price to be shown in the display. If you wish, add the Product reference field to the teaser – this will provide the Add to Cart button.

For each product, create a Product display node.

Enable shopping cart and currency selector blocks

I added Currency Selector and Shopping Cart to Sidebar first.

Create the Rule that will make the Currency Selector work

The Currency Selector block will set the site user’s currency preference.

In order to change the prices displayed when the user changes currency, we need to set up a Rule.

Import the following Rule:

admin/config/workflow/rules/reaction/import

{ "commerce_multicurrency_set_currency_price_eur" : {
"LABEL" : "Set the currency price to EUR",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-9",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
"ON" : [ "commerce_product_calculate_sell_price" ],
"IF" : [
{ "data_is" : { "data" : [ "site:commerce-currency" ], "value" : "EUR" } },
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "commerce_price_eur"
}
},
{ "NOT data_is_empty" : { "data" : [ "commerce-line-item:commerce-product:commerce-price-eur" ] } }
],
"DO" : [
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce-line-item" ],
"amount" : [ "commerce-line-item:commerce-product:commerce-price-eur:amount" ],
"component_name" : "base_price",
"round_mode" : "1"
}
},
{ "commerce_line_item_unit_price_currency_code" : {
"commerce_line_item" : [ "commerce_line_item" ],
"currency_code" : "EUR"
}
}
]
}
}

Cache pages for anonymous users

If your site caches pages for anonymous users (as it should: admin/config/development/performance) then you will experience a problem with the Select currency drop-down for anonymous users: you change it, but nothing happens – the currency remains the same.

I noticed the problem when I noticed the currency switcher not working for anonymous, but working fine when logged in.

The issue and a solution to it are discussed here: http://drupal.org/node/1516128

Posted in drupal

php: formatted debug_backtrace()

This is a nicely-formatted debug_backtrace() I use to investigate where my code is being called from:

array_walk(debug_backtrace(), create_function('$a,$b', 'print "<br /><b>". basename( $a[\'file\'] ). "</b>   <font color=\"red\">{$a[\'line\']}</font>   <font color=\"green\">{$a[\'function\']} ()</font>   ". $a[\'file\'];'));

Posted in php

git

My git notepad.

Avoid old mode new mode messages in git diff

http://stackoverflow.com/questions/1257592/removing-files-saying-old-mode-100755-new-mode-100644-from-unstaged-changes-in

edit .git/config and set:
filemode = false

Posted in git

Installing Drupal on Ubuntu

Here are my notes for installing Drupal on Ubuntu.

These are intended as a starting point for people currently using Windows who would like to try out Linux, install LAMP, and then install Drupal using drush.

https://docs.google.com/document/d/1zWTiV4uZjvy71AMK74PKqf4wd_7Vm2UOLxd3DdQfC4Q/edit

The initial steps are:

http://www.ubuntu.com/download
https://help.ubuntu.com/community/ApacheMySQLPHP

Once you have Drupal installed on your local machine, you will want to learn as much as you can about the modules that make up a useful Drupal installation. The screencasts from Node One are how I learned Drupal. They’re excellent.

http://nodeone.se/learn-drupal

Posted in drupal

Drupal: dynamically change site name

Today I needed code that would dynamically set the $site_name variable, changing the site name of a drupal site temporarily on certain nodes.

It took a while to find, but here is a working solution. Somehow it seems a bit ‘wrong’, but it works nonetheless.

$GLOBALS[‘conf’][‘site_name’] = ‘new site name’;

Thank you to: http://drupal.org/node/253447.

Posted in drupal