Wednesday, December 13, 2017 02:15 am EST

Drupal 7

Bri's picture

Drupal Root Path To the File System

If you are ever in need of the root path of your drupal installation as a file system path, you can use the constant DRUPAL_ROOT in Drupal 7.

This might come in handy for requiring files or includes that have different paths for different environments, such as local, staging, or production sites.

For example, when working locally on a mac, the contents of DRUPAL_ROOT might contain something like:

/Users/bri/Sites/MAMP/mysite

But when I want to put that code in production on a linux box, then the content of the DRUPAL_ROOT might be:

/var/www/mysite/html

Bri's picture

Theme Files to Open in a new window based on Mime Types

There is a thread on drupal.org that describes how to theme drupal 6 filefields and Drupal 7 files to have them open in a new window based on the mime type. I am posting this here so that I can find it easier the next time I need to do so. I didn't write this code. I haven't tried the Drupal 6 code, but the thread appeared to have several people confirm that it worked. I myself can confirm that the code for drupal 7 works.

Add one of the following to your template.php file in your theme.

For Drupal 6 file fields

  
Bri's picture

Drupal 7 Views Contextual Filters to Create a Summary of Taxonomy Terms

Here I want to setup a page with a few views. I want to create a page of node teasers of some sort, perhaps with some exposed filters, but I also want a block that shows a summary of my nodes. I want the block to show how many nodes are in a particular taxonomy. This is nice to do with a taxonomy of States or "types" and acts as a "view nodes by type" action. This can be done with a regular text field as well, but if you are using a taxonomy it is a little trickier. Here are some basic instructions to create a page that looks like the following:

Bri's picture

Change the submitted variable in drupal 7

Go to: /admin/config/regional/date-time/formats/add
Create desired time format, i.e. l, d/m/Y or see http://id.php.net/manual/en/function.date.php for available options.
Add format.
Go to: /admin/config/regional/date-time
Set medium data type into the desired one.

Bri's picture

Theming the Contact Form in Drupal 7 (contact_site_form)

Theming the contact form in Drupal 7 is almost the same as most people did it in Drupal 6, but the one change through me for a loop for quite awhile.

Using Drupal 6, most people would add some code to their template.php file and create something like the following:

DRUPAL 6

function myTheme_theme() {
  return array(
	'contact_mail_page' => array(
					'arguments' => array('form' => NULL),
					'template' => 'contact-form',
					),
	);
}
function myTheme_preprocess_contact_mail_page(&$vars)
{
	$vars['name'] = drupal_render($vars['form']['name']);	
Syndicate content