Wednesday, May 18, 2011

Sample Interview Questions for Drupal Themer

General questions

1. What is a theme override?
2. What's the difference between a theme override and a template file?
3. Where is the place for placing a theme override?
4. Where is the place for placing a template file? What are the differences in template files on D5 and D6?
5. What are the template files involved in theming an Ubercart invoice?
6. Have you worked with 960gs before? If not, have you worked with any kind of grid layout framework? Even if you have no experience with this, you should take a quick look at both the drupal theme and the 960gs framework and comment how you see working with 960gs can help you when developing a drupal theme.

Questions on theme development
A simple e-commerce site is needed - all the functionality has been coded. Regular static pages (about us, contact us, terms and conditions etc) plus a product with several fields (title, size, color, body, main image, additional images, price, SKU, etc.)

We assume you have knowledge of CCK & Views as those modules would be used both for creating the content types and working on different displays that will probably need to be themed. We are going to use imagefield module for the images and imagecache module for thumbs and other images sizes.

In your answers, we are looking for certain basics on drupal theme development, you don't need to provide any code, just brief answers that indicate how you would handle each point. Please explain the specifics involved in a proper drupal theme, such as template files that you might use, what alternatives around drupal (modules, etc.) you can suggest or what function (don't need the exact name) you think you would override.

1. How would you work with the main images and the additional images on the theme? What would you do and what templates file are you planning on changing?
2. How would you work on the the theme to selectively display certain fields of the product in a very specific way to match a design, something that's not configurable through the content type display administration section?
3. How would you display the main image with a normal size and additional images as thumbnails just below the main image, in a grid-like form displaying three per row. Also, what would you do if an image swap effect between the thumbnail and the main image is required?
4. If we need a block display up to 6 products in a 3 column scheme on top of the content, how would you do this?
5. How would you theme the checkout page of an Ubercart e-commerce site?

Saturday, May 7, 2011

How Drupal's Menu System Work?

The Drupal menu system drives both the navigation system from a user perspective and the callback system that Drupal uses to respond to URLs passed from the browser. For this reason, a good understanding of the menu system is fundamental to the creation of complex modules.
Drupal's menu system follows a simple hierarchy defined by paths. Implementations of hook_menu() define menu items and assign them to paths (which should be unique). The menu system aggregates these items and determines the menu hierarchy from the paths. For example, if the paths defined were a, a/b, e, a/b/c/d, f/g, and a/b/h, the menu system would form the structure:

a
a/b
a/b/c/d
a/b/h
e
f/g

Note that the number of elements in the path does not necessarily determine the depth of the menu item in the tree.

When responding to a page request, the menu system looks to see if the path requested by the browser is registered as a menu item with a callback. If not, the system searches up the menu tree for the most complete match with a callback it can find. If the path a/b/i is requested in the tree above, the callback for a/b would be used.

The found callback function is called with any arguments specified in the "page arguments" attribute of its menu item. The attribute must be an array. After these arguments, any remaining components of the path are appended as further arguments. In this way, the callback for a/b above could respond to a request for a/b/i differently than a request for a/b/j.

For an illustration of this process, see page_example.module.
Access to the callback functions is also protected by the menu system. The "access callback" with an optional "access arguments" of each menu item is called before the page callback proceeds. If this returns TRUE, then access is granted; if FALSE, then access is denied. Menu items may omit this attribute to use the value provided by an ancestor item.

In the default Drupal interface, you will notice many links rendered as tabs. These are known in the menu system as "local tasks", and they are rendered as tabs by default, though other presentations are possible. Local tasks function just as other menu items in most respects. It is convention that the names of these tasks should be short verbs if possible. In addition, a "default" local task should be provided for each set. When visiting a local task's parent menu item, the default local task will be rendered as if it is selected; this provides for a normal tab user experience. This default task is special in that it links not to its provided path, but to its parent item's path instead. The default task's path is only used to place it appropriately in the menu hierarchy.

Everything described so far is stored in the menu_router table. The menu_links table holds the visible menu links. By default these are derived from the same hook_menu definitions, however you are free to add more with menu_link_save().

Sunday, May 1, 2011

How to Set Up a Multisite Drupal Installation?

Multisite 10 minute Install:
  • Server: LAMP
  • SSH (telnet) Client: ssh (PuTTY if you are using Windows to access your LAMP host)
  • Must have root access to your server.
If website in question is an addon domain, i.e., addon.example.com, then substitute "addon" for "www" in steps below.
For list of Linux commands visit: http://www.oreillynet.com/linux/cmd/ or http://www.ss64.com/bash/
Here we go:
[login via ssh / PuTTY]

Debian (Ubuntu)

Debian and offshoot distributions (e.g. Ubuntu) make installation and configuration very easy. This was done on a Debian distribution, Ubuntu should work identically.

Installation

Assumption: apache2 and mysql are already installed. If not, use apt-get install to install and configure them.
# apt-get install drupal6
Answer the questions. This will install everything necessary to run drupal and do the basic configuration, including creating an empty database for drupal.
  • Configure database for drupal6 with dbconfig-common? [YES]
  • Database type to be used by drupal6: [mysql]
  • Password of your database's administrative user: [enter mysql root password]
  • MySQL application password for drupal6: [create a password for your drupal6 db]
  • (enter the password again for verification)
You now have a basic unconfigured Drupal6 installation using the database drupal6 and accessible at http://www.example.com/drupal6. Do not use it. This is the "prototype" installation that we will use to create the sites we really want to use.

 

Create Site Databases

The easiest way to create databases for your sites is to use dpkg-reconfigure and answer the questions.
# dpkg-reconfigure drupal6
  • Re-install database for drupal6? [YES]
  • Database type to be used by drupal6: [mysql]
  • Connection method for MySQL database of drupal6: [unix socket]
  • Name of your database's administrative user: [root]
  • Password of your database's administrative user: [enter mysql root password]
  • username for drupal6: [ENTER YOUR DB SITE *USERNAME* HERE (e.g. mysite)]
  • database name for drupal6: [ENTER YOUR DB *SITE* NAME HERE (e.g. mysite)]
Notes:
  1. Repeat the above for each site you want to support.
  2. I used the same name for the database and the site. KISS.
  3. Don't use periods (e.g. mysite.com is a bad choice). If you want to spell out the whole name, use underscores instead of periods (e.g. mysite_com).
  4. The above method ends up using the same site database password for all the sites you create. Advice: use mysql-admin (or mysql) to use different passwords for each site. 

    Configure Apache2 for Sites

    Before you jump to configure your virtual hosts do not forget to add host names in /etc/hosts file.

    your.ip.add.res   vritualhost_1.name
    your.2.ip.add.res virtualhost_2.name
    Apache2 needs to be configured to support vhost access to your new sites.
    Create vhost site configuration files in /etc/apache2/sites-available/
    #
    # Virtual hosting configuration for Drupal
    #


    ServerAdmin [your email address]

    DocumentRoot /usr/share/drupal6/
    ServerName [your vhost#1 name]
    ServerAlias [if you want to support www.example.com and example.com]
    RewriteEngine On
    RewriteOptions inherit



    ServerAdmin [your email address]

    DocumentRoot /usr/share/drupal6/
    ServerName [your vhost#2 name]
    ServerAlias [if you want to support www.example1.com and example1.com]
    RewriteEngine On
    RewriteOptions inherit


    [...repeat for all your vhosts]
    Notes:
    • Modify the above items that are in [square brackets].
    • You likely will want to support port 443 (https) as well. See Apache documentation for detailed instructions.
    • I've chosen to put all the vhosts in one file named drupal. You may want to use one file per vhost.
    Sym-link the drupal file in the sites-enabled directory to enable it in your site:
    # cd /etc/apache2/sites-enabled
    # ln -s ../sites-available/drupal .

    ...and reload Apache2 to pick up your configuration changes...
    # /etc/init.d/apache2 reload

    Create Drupal Site Configurations

    We need to create Drupal configurations for each site by copying the default configuration to the Drupal site subdirectory.
    # cd /etc/drupal/6/sites/
    # cp -a default [site1.com]
    # cp -a default [site2.com]
    :
    :

    ...and edit the configurations to use the right database, MySQL user name, and password...
    # vi site1.com/dbconfig.php
    # vi site2.com/dbconfig.php
    :
    :
    Notes:
    • Modify the above items that are in [square brackets].

     

    Run Drupal and Configure Your Sites

    Browse to your sites, running install.php (e.g. http://www.example.com/install.php) to configure them.

     

    Manual

    Get to location where Drupal core will be located:
    [/]# cd /var/www
    Upload Drupal core:
    "x.x" should be replaced with the version of Drupal you're installing, e.g. "5.2"
    [/var/www]# wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-x.x.tar.gz
    Unpack Drupal core:
    [/var/www]# tar -zxvf drupal-5.2.tar.gz
    Move contents of Drupal core (including .htaccess) to html:
    [/var/www]# mv drupal-x.x/* drupal-x.x/.htaccess /var/www/html
    Clean-up:
    [/var/www]# rm drupal-x.x.tar.gz

    [/var/www]# rm drupal-5.2
    Create the files directory per Drupal instructions and change permissions (will change permission again after install):
    [/var/www]# cd html

    [/var/www/html]# mkdir files

    [/var/www/html]# chmod 777 files
    Make directories that will hold custom and contributes modules and themes:
    [/var/www/html]# cd sites/all

    [/var/www/html/sites/all]# mkdir modules

    [/var/www/html/sites/all]# mkdir themes

    [/var/www/html/sites/all]# cd modules

    [/var/www/html/sites/all/modules]# mkdir custom

    [/var/www/html/sites/all/modules]# mkdir contrib

    [/var/www/html/sites/all/modules]# cd ../

    [/var/www/html/sites/all]# cd themes

    [/var/www/html/sites/all/themes]# mkdir custom

    [/var/www/html/sites/all/themes]# mkdir contrib
    Create directory "www.example.com.tld":
    [/var/www/html/sites/all/themes]# cd ../

    [/var/www/html/sites/all]# cd ../

    [/var/www/html/sites]# mkdir www.example.com
    Change permission of "settings.php" per Drupal instructions and copy "settings.php" in default to www.example.com:
    [/var/www/html/sites]# cd default

    [/var/www/html/sites/default]# chmod 777 settings.php

    [/var/www/html/sites/default]# cd ../

    [/var/www/html/sites]# cp -a default www.example.com
    Create database and user with permissions:
    [/var/www/html/sites]# mysql

    mysql> CREATE DATABASE wwwexamplecom_drupal;

    mysql> GRANT ALL PRIVILEGES ON wwwwexamplecom_drupal_drupal.* TO 'wwwexamplecom_drupal_myusername'@'localhost' IDENTIFIED BY 'mypassword';
    mysql> \q
    Go back to PuTTY to chmod on settings.php in www.example.com:
    [/var/www/html/sites]# cd www.example.com

    [/var/www/html/sites/www.example.com]# chmod 755 settings.php

    [/var/www/html/sites/www.example.com]# logout
    What next?:
    • Make changes to "settings.php" in www.example.com? I've read that it's not necessary to make changes to setting.php.
    • Make changes to "httpd.conf" in /usr/local/apache/conf?
    I've been using WHM to create accounts, putting Drupal in public_html and having no problems. But when it comes to parting from the WHM abstraction and getting multisite set-up correctly this is the end of the proverbial road for me.
    Could use help...:
    1. Help making improvements to steps articulated above
    2. Help with next steps so that I/we can get on to grander things, like creating modules, custom themes, profiles, (and maybe - just maybe - spend some time working on business strategy :-)

    TESTING YOUR MULTISITE INSTALLATION(S)
    Now that we have successfully setup both our multisite installations (1 & 2), we can proceed to test our installation to see how this will benefit us in the future for accomplishing tasks much quicker between sites that rely on the same code base or share similar modules & themes.
    1. Download the latest version of your favorite drupal 6 module. Here we will be using "Views".
    2. Place the "Views" module inside of your main sites drupal modules folder: multisite-main/sites/all/modules/views, this module will now be shared across all multisite installations. Same goes for any themes you setup in the /sites/all/themes folder. You may now enable it for individual sites by visiting your sites "admin/build/modules" page. (ie. http://multisite-1/multisite-main/admin/build/modules).
    3. Likewise, if you do not want to share modules/themes across sites you would create a "modules" or "themes" folder inside of your multisite-1 or multisite-2 folder, and place your site specific modules inside of them.