Pages

Wednesday, August 22, 2012

Working with Stark in Drupal 7


How to create an 'unmolested' Drupal starter theme using Stark in Drupal 7.
How to create an 'unmolested' Drupal starter theme using Stark in Drupal 7.
Before we begin I will assume that you will following the the links provided for further reading. This guide is to give you a starting point on designing Drupal from scratch utilizing Stark.
The files referenced in this guide are based on a Linux, Debian Squeeze, server. A development server is recommended when testing or creating any theme/module.
The Stark theme provided with Drupal is generally used as a troubleshooting tool for CSS or Javascript. From a designing perspective the usefulness of the Stark theme is based on Drupal's default HTML markup and CSS styles.
If starting a theme from scratch is not your cup of tea, you can always check out starter themes such as Zenor Fusion. You can also view our article on HTML5 Drupal starter themes We will by pass the Drupal installation process and assume that you have a Drupal 7 version already set up.

Preparing your custom theme registry

If you haven't done so already create a custom theme directory
sudo mkdir /var/www/(your drupal 7 site)/sites/all/themes
Now the first thing we want to do is copy stark from the themes folder found in /var/www/(your drupal 7 sit)/themes/stark to your theme directory /var/www/(your drupal 7 site)/sites/all/themes
sudo cp -r /var/www/(your drupal 7 site)/themes/stark /var/www/(your drupal 7 site)/sites/all/themes The stark theme contains the following files:
  • layout.css - Your css file
  • logo.png - Default drupal logo
  • README.txt - A Read me file that further explains Stark
  • screenshot.png - A screenshot of your theme. Visable from the admin panel.
  • stark.info - A required file which provides theme information
From this point you may want to rename Stark. When renaming a theme make sure the directory and the .info all contain the theme name. For example if I want to name my theme "example"
The the theme directory folder will be: /var/www/(your drupal 7 site)/sites/all/themes/example
Your .info file will be: /var/www/(your drupal 7 site)/sites/all/themes/example/example.info
You may also want to edit the .info name to avoid confusion when enabling the theme. sudo gedit /var/www/(your drupal 7 site)/sites/all/themes/example/example.info
And change name = Stark
To
name = Example
Once we have our Stark folder in our theme directory we can begin to add a few core templates.

Core templates

Drupal 7 has default templates (.tpl.php) files that are provided by core. A few templates files worth including into your new custom theme are:
  • block.tpl.php "/var/www/(your drupal 7 site)/modules/block/block.tpl.php"
  • comment.tpl.php "/var/www/(your drupal 7 site)/modules/comment/comment.tpl.php"
  • node.tpl.php "/var/www/(your drupal 7 site)/modules/node/node.tpl.php"
  • taxonomy-term.tpl.php* "/var/www/(your drupal 7 site)/modules/taxonomy/taxonomy-term.tpl.php"
  • page.tpl.php "/var/www/(your drupal 7 site)/modules/system/page.tpl.php"
  • maintenance-page.tpl.php "/var/www/(your drupal 7 site)/modules/system/maintenance-page.tpl.php"
  • region.tpl.php "/var/www/(your drupal 7 site)/modules/system/region.tpl.php"
  • html.tpl.php "/var/www/(your drupal 7 site)/modules/system/html.tpl.php"
You will also need to create the necessary "template.php" file and have it reside in your custom theme folder.

Removing Formatting Guidlines for Drupal 7


A common question that comes up when it comes to Drupal is removing the formatting guidelines.
1. Removing formatting guidelines through a Drupal module.
The first option is getting the Better Formats module.
  • Enable the module
  • Once enabled you will need to navigate to your permissions menu: admin/user/permissions
  • Under the permission module search for the term "better_formats module" under this header you will get the option to enable or disable display format tips, format selections for nodes etc.
Please note that the Drupal 7 version is currently under heavy development and the above solution works best for the Drupal 6 version.
2. Theme Template File
Since the first method does not work best in Drupal 7. A good alternative is to input the following code in your themes template.php file.
/**
* Remove the comment filters' tips
*/
function myTheme_filter_tips($tips, $long = FALSE, $extra = '') {
  return '';
}
/**
* Remove the comment filter's more information tips link
*/
function myTheme_filter_tips_more_info () {
  return '';
}
/**
* Remove the comment filters' tips
*/
function myTheme_filter_tips($tips, $long = FALSE, $extra = '') {
  return '';
}
/**
* Remove the comment filter's more information tips link
*/
function myTheme_filter_tips_more_info () {
  return '';
}

Using the Testing framework in Drupal 7


If you are familiar with the SimpleTest module then you may already be aware of Drupal's testing Framework. In Drupal 7 the testing framework can now be found in core.
If you are familiar with the SimpleTest module then you may already be aware of Drupal's testing Framework. In Drupal 7 the testing framework can now be found in core. The purpose of this framework is to test the logic of custom modules or any add-on modules. We will do a quick walkthrough of the framework and look at some of the hooks that your custom module may want to implement to interact with the testing framework. For a complete discussion of building tests using the testing framework, see the simple test documentation.

Testing Checklist

Make sure:
  • The CURL extension for PHP is enabled.
  • A memory_limit of at least 256 MB should be configured.
  • “Testing” module is enabled.
After you have completed this initial configuration, you are ready to run tests. You can run tests by navigating to the test manager found in Administartion >> Configuration >> Development >> Testing or by navigating directly to admin/config/development/testing.

Running tests

The interface for testing will look as followed: [image – testing 1] The way this works is to select the test you would like to perform and click Run tests at the bottom of the page. This page will list Drupal core and all active modules that are available for testing. After the tests are run, a report will be presented to you describing the results of the test. [image – testing 2]

Creating Tests

To create a test for your module, you would need to create a PHP file that uses the naming convention, modulename.test where modulename is the name of your custom module. Within this file, you will create a class that inherits from DrupalWebTestCase. The DrupalWebTestCase features an internal browser that can be used to navigate throughout your test site.
The class created will allow you to create tests and set up your test case prior to running the tests, and clean up after the tests completed. If you would like to interact with the testing framework the use of hook_test_finished, hook_test_group_started, hook_test_group_finished can be utilized. The first hook, being the hook_test_finished is a hook that is called when a test has finished.
The code will look like: hook_test_finished($results)The hook_test_group_started is a hook that is called when testing a specific test group has started. This hook can be utilized as: hook_test_group_finished(). The hook_test_group_finished is a hook called when testing of a specific test group has completed. This hook can be called by using hook_test_group_finished ()This just a small guide as to the capabilities of the testing framework now found in Drupal 7 core. To get a further understanding of the testing framework and how to get started you can read Getting Started with SimpleTest.

Tuesday, August 21, 2012

Installing PECL UploadProgress for Drupal 7


If you are running your own server, you may encounter a disabled notice relating to Upload Progress. Here is how to correct it
This brief guide will help you install "PECL uploadprogress" on a Debian system.
1. Install make and the development files for php5:
sudo apt-get install make php5-dev
2. Configuration, compilation and installation is done completely automatically with the command:
sudo pecl install uploadprogress-1.0.1
After a few seconds the result should be:
Build process completed successfully
Installing '/usr/lib/php5/20090626+lfs/uploadprogress.so'
install ok: channel://pecl.php.net/uploadprogress-1.0.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=uploadprogress.so" to php.ini
In order to keep the php configuration enter:
echo -e "extension=uploadprogress.so" > /etc/php5/apache2/conf.d/uploadprogress.ini
Now reload the Apache configuration with:
sudo /etc/init.d/apache2 reload
The Drupal status page now displays:
Upload progress Enabled (PECL uploadprogress)