Drupal 7 site building case study

Wireframes #

In this post we’ll look at some wireframes, and then build the three pages given using contrib Drupal modules.

We may skip or change some elements from the wireframes to fit our purposes.

Source for these wireframes: Park & Bond on Behance (2011-09-21)

Homepage #

The first page we are going to build is the homepage. The main blocks to be displayed are:

wire_home.png

Category page #

The category page mainly shows products for a single category. The blocks are:

wire_category.png

Product detail page #

The product detail page shows a single product, and some related information. The blocks are:

wire_detail.png

Setup #

Required modules #

Let’s install a few modules first. Using drush:

$ drush en panels panels_mini views views_ui views_content page_manager ds nodequeue smartqueue entity entityreference link webform hierarchical_term_formatter

Tip: This command is meant to “enable” a few modules, but if they don’t exist in your files, Drush will download them first. Also, a few more modules are enabled if they’re dependencies (ctools, for example).

We will also need these modules to work with Features:

$ drush en features features_uuid

Let’s explain a bit what each module does.

Noteworthy modules #

Homepage #

Let’s build the homepage. Go to Structure -> Pages -> Add custom page, and let’s create a Panel. Make sure you check the “Make this your site home page” checkbox.

A_home_panel_1.png

Now let’s choose a layout. We could create a new layout in the theme, or we could use the “Flexible” layout from the “Builders” category, which lets us create regions dynamically through the interface, but for now let’s stick with “Two column bricks”, which looks like it has appropriate regions for our purposes.

A_home_panel_2.png

After a couple of screens, we arrive at the “Content” page. We’ll come back to it later to add the blocks we create in the appropriate places.

Header mini-panel #

To create the header (some static content, title, main menu, search form, and eventually some links for managing the user account and shopping cart functionality), we will use a mini-panel. The reason is reusability: when we need to change it, we will only change it in one place and it will update throughout the site.

The process is very similar to creating a new panel. From Structure -> Mini panels -> Add:

A_header_minipanel_1.png

Let’s choose an appropriate layout:

A_header_minipanel_2.png

Let’s add the site logo first. You can find it in the “Page elements” category:

A_header_page_title_2.png

Now, following the same process, let’s add some more blocks:

And, finally, a “New custom content” block for the “Top” region. For now this is all we’ll do in this region.

A_header_top_1.png

A_header_top_2.png

Finally, click on Preview to see how it looks like:

A_header_minipanel_3.png

It might not be obvious by looking at it, but all elements are there. Finally, click on “Finish” to save our work.

Main slideshow #

For the slideshow we will use a nodequeue to let users edit the displayed content.

The nodes will belong to a specialized content type that we will call “Slide”. Let’s create that first. From Structure -> Content types -> Add content type, let’s create it and click on “Save and add fields”.

A_slide_1.png

In addition to the fields created by default, we will need an image field, a link (to show a button linking to any page in the site), and a reference field to show the category above the title. We quickly create the Category taxonomy to accommodate the reference field.

A_category_1.png

And now we go back to the content type and create all the fields. Note that the type for the category field is “Term reference” and not the new “Entity reference”. This is because later we’ll have problems creating nodequeues (there is a new “entity queue” module that might soon replace “nodequeue”).

A_slide_2.png

Next step is creating the nodequeue. From Structure -> Nodequeues -> Add simple queue:

A_slideshow_1.png

Now we can create the slideshow view. From Structure -> Views -> Add new view, we create the view without creating a page nor a block. The display type we will use is “Content pane”, since we will want to place the view in a panel, so we have to manually add the display. After tweaking the view options, this is what we have:

A_slideshow_2.png

Things to note from the view configuration:

A_slide_3.png

Note that we had to select a layout (bottom of this page, not visible in the screenshot) so that the Title field shows as an option.

We now have a slideshow, ready to be placed in the Homepage panel.

Next is the “featured products” block, which shows a total of 5 products from a single category (chosen by a content editor), the first of which is shown in a bigger, more detailed format than the rest.

For this we’ll create two view modes for the Product content type (which we’ll also need to create), a set of nodequeues (one for each category), and a view to show them. The view will have a contextual filter, so that the results come from a single category, specified in the homepage panel configuration.

Let’s configure the Product content type with these fields:

The result is shown below:

A_product_1.png

Now let’s create a nodequeue called “Featured products”. Here we will use a “smart queue”, specifically a “taxonomy queue”, which will create separate lists for each term of the Category taxonomy. We restrict the nodequeue to only accept Products.

A_featured_products_1.png

Now, let’s create the two view modes that will display the products. Here we make a conscious decision to create two new view modes and not reuse any of the existing ones. We decide this because these modes are specific to products, and they will probably not be used in many places in the site. Teaser, for example, sounds like it could be shared between different content types and show nodes in a more standardized way.

Let’s create the two view modes and call them “Product big” and “Product small” (only the first shown here).

A_product_big_1.png

Now we can go to the display configuration for the Product content type, and select both view modes so that we can customize the display for them.

A_product_display_1.png

Now we can configure them to show the appropriate fields in each case, according to the wireframes.

A_product_big_2.png

The final step is, then, to create the view. Here it is, finalized:

A_featured_products_2.png

Some things to note:

That’s it, the featured products view is all set and ready to be placed in the homepage panel.

Blog sidebar #

The blog sidebar is a form with a view below it. For the form we’ll use the Webform module, which gives us the ability to create arbitrary forms for our site as nodes. For the view we’ll create a Blog Post content type, and create the view to show the latest posts using the Teaser view mode.

After enabling the Webform module, you will see a Webform content type. We can simply create a node from this content type, and set up its fields in the Webform tab. The specifics are outside the scope of this course, but it should look like this:

A_webform_1.png

One thing that needs to be specified in the “Form settings” tab is that the webform should be available as a block. This will allow the form to be placed in the homepage panel configuration.

Next is the blog view. The configuration for the content type, teaser display, and view is shown below.

A_blog_1.png

A_blog_2.png

A_blog_3.png

Featured article #

Drupal provides a “promote to homepage” checkbox for nodes. We can use this property and select the latest promoted article in a view, like so:

A_promoted_article_1.png

Secondary products #

This view will be created as the second display of the Products view we created before. It receives a contextual filter to select the category, and it has some exposed sort options.

A_product_view_1.png

Bottom categories #

The last piece of the puzzle is a list of three links to category pages. Content editors need to be able to select any category, so a nodequeue might be the first option that comes to mind. Except nodequeues only work for nodes. A new module, “Entity queue”, promises to solve this issue, but it’s not stable yet, so let’s do this a different way, one that will hopefully illustrate how panel contexts work. We will manually select three taxonomy terms as “contexts”, and then show them in the appropriate region with a new view mode that we’ll call “Block”.

A_category_block_1.png

Putting everything together #

Let’s go back to the homepage panel configuration.

First, let’s select the bottom 3 categories as contexts. We will also need two more to pass to the product lists:

A_category_block_2.png

A_category_block_3.png

A_category_block_4.png

Now let’s go to “Content” and add everything!

A_home_content_1.png

Some things to note:

A_home_content_2.png

Category page #

In our structure, “Category” is a taxonomy vocabulary, so the Category page is actually the “view taxonomy term” page for that vocabulary.

The Pages configuration interface gives you the option of enabling the term_view panel, which we will use to customize this page.

A_term_view_1.png

Once enabled, go into “Edit” and you’ll see an empty panel. We need to create a variant. Generally when using term_view (and, later, node_view) we want to have a variant for each vocabulary (or content type). So we specify “Selection rules” to make this variant work only when the term is from the Category vocabulary.

A_term_view_2.png

A_term_view_3.png

A_term_view_4.png

The layout we will use is the “Single column” one, since our blocks will cover all the page width. We click on “Continue” a couple more times, and we get to this page:

A_term_view_5.png

Here we set the title to “%term:name”. We can do this because we have a context configured automatically in this panel identified by “%term”, which is the taxonomy term object that the user will see in the final page. So, if we go into the “Clothing” term, “%term:name” will translate to “Clothing”.

Finally, we click on “Create variant”, and then “Update and save”. We will add the blocks later. A category page now looks completely empty.

Editorial content #

For showing editorial content related to the category, we will add an entity reference field to the vocabulary, with the possibility to add 3 items. For now we will only be able to add articles to it.

A_editorial_content_1.png

We will later add this field directly to the panel, using the “rendered entity” formatter to display the articles with an appropriate view mode.

This works the same as the Editorial Content block: an entity reference field in the taxonomy with a maximum of 3 elements.

Products view #

This is the main view for this page. We will not use the existing “Products” view created for the homepage, because the presentation is very different. This view has a lot more functionality, so it deserves to be promoted to a separate view.

A_category_products_1.png

Noteworthy:

Panel config #

We now have everything we need. Let’s put it all in the panel:

A_category_page_1.png

The “Featured products” block has a customizable title (in the wireframe example, the category is “Suits” and this title says “Suiting for Spring”). We do this by adding an extra text field to the taxonomy, and simply including it in the panel configuration.

Product detail page #

The detail page works very similar to the Category page, but uses the node_view panel instead of the term_view one. This is the simplest of the three, so we’ll keep it short.

The process of enabling the panel and creating a variant is the same as before, but this time we configure the selection rule to filter by content type.

Each product has a category, and the categories can have parents (e.g. “Apparel -> Suits”). This block shows the product’s category and its parents. A quick Google search returns the Hierarchical Term Formatter module, which seems perfect for our needs. It provides a new formatter, which can be configured right on the panel to show the Category field for the node.

A_hierarchical_1.png

Product information #

This is just fields shown in the panel. We could build a mini-panel, or play around with the layout, but the idea is the same: showing fields from the product node.

This is a new display in our “Products” view that receives two contextual filters:

  1. The current node ID, configured as “Exclude”. This makes the view not show the same product the user is viewing in the whole page, which wouldn’t make sense.
  2. A term ID to select products from. This could change in the future to a more complicated “related” logic, but for our purposes it’s enough to show products from the same category.

A_related_products_1.png

Bottom categories #

We copy the same functionality we have in the homepage. There could be some logic here to select the three categories to be shown (a view with some specific criteria depending on the product node), and once that’s defined it can easily be changed.

Panel configuration #

This is the final panel configuration for the Product detail page. We used the same layout as the homepage.

A_detail_1.png

Features #

In order to do clean deploys we use Features to encapsulate all that we’ve been doing. We will use the “JBS” prefix to separate our features from other modules; this is generally considered good practice.

For this demo we’ll have the following features:

JBS Model #

Let’s create the “model” feature then. We will only show how the “recreate” screen looks like; this shows what’s in the feature. Note that Drupal automatically adds dependencies, so for example when including the “Product” content type, it will add the “field_brand” and the rest of the fields.

A_feature_model.png

Note that this feature includes the “Ask Anything” webform. This is actually a node, and requires the “uuid” and “features_uuid” modules to be enabled, including a configuration (in admin/config/content/uuid_features) so that webforms are exportable to features.

JBS Pages #

This contains all the panel configuration, views, and display suite settings. This is normally split into different features, so for example a “JBS Blog” feature could contain the “Blog post” content type and related views and other objects.

A_feature_pages.png

JBS Test content #

This feature contains nodes and taxonomy terms. These were generated by the “Devel generate” module.

A_feature_test_content.png

Downloads #

You can download the features used in this exercise here. If you do a clean Drupal 7 install, put these into the modules folder, and enable them using drush, all dependencies will be downloaded automatically and you should see the same site we’ve been working on.

 
7
Kudos
 
7
Kudos

Now read this

Technical skills in 2015

Recently it became clear to me that tracking technical skills year by year could be an interesting exercise. In this industry you get to work with so many technologies that you later forget, that this idea makes sense not only to stay... Continue →