Drupal for Education and E-Learning(Second Edition)
上QQ阅读APP看书,第一时间看更新

Installing modules and themes

As you run and administer your Drupal site, you will need to install and enable different contributed modules and themes. To understand how to install contributed modules and themes, we will need to take a brief look at the Drupal's directory structure, as pictured in the following screenshot:

As seen in the preceding screenshot, the directory structure contains seven directories, in addition to 20 files in the base folder of the Drupal installation.

Files

On looking at the files in the base folder of the Drupal installation, we will see three different types of files: an .htaccess file, a series of .txt files, and a series of .php files. The .htaccess file contains specific settings that help ensure that your site runs smoothly; the .txt files (with the exception of robots.txt) contain all the information about Drupal and the .php files are all part of the codebase that allows your site to run.

For most sites, you will never need to open or edit any of these files. Of all the files in the base directory of your Drupal installation, the only two that could ever require editing are the .htaccess and robots.txt files. However, tweaks to these files should only be done when absolutely necessary, and you should always back up these files before attempting any modifications to them.

Directories

On looking at the directories of the Drupal installation, we will focus on three directories: modules, themes, and sites.

Core modules and themes

The modules and themes directories of the core Drupal installation, indicated by the first and last arrows in the preceding screenshot, contain the core modules and themes.

Tip

Under no circumstances should anything ever be added into these directories.

The sites directory

The sites directory, indicated by the middle arrow in the preceding screenshot, contains the directories into which we install the additional modules and themes. The default Drupal installation, as shown in the following screenshot, comes with two subfolders in the sites directory: all and default.

The default directory contains our settings.php file; the all directory is where we will put contributed themes and modules. Refer to the following screenshot:

Steps for adding modules and themes

To add a module or a theme, follow these four steps:

  1. Download the theme or module from http://drupal.org.
  2. Decompress the theme or module. They are packaged on drupal.org as tar.gz files and needed to be extracted before they can be installed.
  3. Upload the theme or module to your site.
  4. Enable modules at admin/modules or themes at admin/appearance.
Step 1 – downloading

All modules and themes are downloaded from their project page. In this example, we will download and install the Views module, the Chaos tool suite (Ctools), and the Advanced Help module. To get the source code, we will navigate to the Views project page at http://drupal.org/project/views, (as shown in the following screenshot), the Ctools project page at http://drupal.org/project/ctools, and also the Advanced help project page at http://drupal.org/project/advanced_help:

Tip

The Drupal 7 version of Views requires the Ctools module to function. The Drupal 6 version of the module did not require this module. Views has been moved into Drupal's core for Drupal 8.

The Views project page shows the official releases as well as other stable releases and development versions. The Status column, indicated by section 1 in the preceding screenshot, gives you information about the different versions that are available. In most cases, you should only use official releases that have a status of Recommended. Also, the version of the module needs to match up with the version of Drupal; for example, only the 7.x Versions of modules work with Drupal 7.

In this case, we want to install Views for Drupal 7, so we click on the Download link, indicated by section 2 in the preceding screenshot, to download the module.

Then, repeat these steps for the Ctools module at http://drupal.org/project/ctools and the Advanced help module at http://drupal.org/project/advanced_help.

Tip

To keep your downloaded code organized, create a folder to use specifically for this purpose.

Step 2 – decompressing

Once you have downloaded the code from drupal.org to your computer, decompress the file. On a Mac or Linux machine, this will occur automatically; on a PC, use 7-zip (an open source utility available at http://www.7-zip.org) to decompress the tarball into the Views directory.

Step 3 – uploading

Open your FTP client and upload the directory containing the module (in our case, Views) to the sites/all/modules directory, as shown in the following screenshot:

If you were uploading a theme, you would upload the theme folder into the sites/all/themes directory.

Step 4 – enabling

Once the modules have been successfully uploaded into your sites/all/modules directory, click on the Modules link or navigate to admin/modules, as shown in the following screenshot:

This screen gives a breakdown of the modules that you have uploaded into your sites/all/modules folder.

To enable the Advanced help module, select the checkbox next to Advanced help. To enable the Ctools module, select the checkbox next to Chaos tools. To enable the Views module, select the checkboxes next to the Views and Views UI modules. Click on the Save configuration button to save your settings and enable your modules. You will receive a confirmation message at the top of the screen.

Tip

Many projects are actually a collection of related modules. For example, the Views module comes with two related modules. Before you install any module, you should read the README.txt and INSTALL.txt files that come with most modules. These files are usually located in the base directory of the project download.

Configuring modules and themes

Now that we have finished installing modules and themes, we need to configure them.

Modules

Once you have enabled a new module, you should check to see if there are any configuration options for the module. To do this, look in the OPERATIONS column of the Modules page.

By looking at the page, we see that both the Views module and the Advanced help module have links to Permissions. These permissions are covered in more detail later in this chapter, in the Creating views section.

Themes

After you have uploaded a theme into the sites/all/themes directory, you will need to enable it via the Appearance link or by navigating to admin/appearance. The themes and their different settings are covered in more detail in Chapter 14, Theming and User Interface Design.

Modules and themes – a summary

As described in this section, installing modules and themes involves four steps:

  • Downloading
  • Decompressing
  • Uploading
  • Enabling

Modules are uploaded into sites/all/modules and themes are uploaded into sites/all/themes.

Modules, once uploaded, are enabled at admin/modules. Themes, once uploaded, are enabled at admin/appearance. Although different modules and themes will have the varying configuration settings, the previous steps will remain constant for any module or theme you use on your site.