PACS Notes September 17, 2011 Introduction to Drupal 1. Download and install XAMPP, MAMP or a similar local web server package, or set up hosting on a service. 2. Go to drupal.org, locate the latest Version 7 download and download it. Currently this is 7.8, as of 9/12/11. There are two zip file options. Select the one you like and download. 3. Unzip the drupal package to the htdocs folder. This is the equivalent of the root of your hosted website, for example, http://www.mysite.com. 4. Navigate to /htdocs/drupal-site-name/sites/default folder. You will find a file called default.settings.php. 5. Copy the default.settings.php file into the same directory (/sites/default) and name the copy settings.php. Note that you cannot just rename the settings.default.php file. Drupal needs both files to work. 6. If necessary (i.e., on a hosted site) change the permissions on the settings.php file to make it writeable. If you do need to do this, be sure to change it back after the install process is finished. 7. Start your web server package if you are installing locally. 8. If using MAMP, a browser window will be open. Select the phpMyAdmin tab. If XAMPP, open a browser window and go to localhost/phpmyadmin. 9. Create a new database. Then select the Privileges tab and create a new user. Use these settings: Host - local. User name - whatever you want. Password - whatever you want. DO NOT click the Generate button or a password will be generated for you. Be sure to check the Check All in Global Settings. Then click Go. You will see a message that you have created a new user on the database. 10. Be sure you know the name of your database, user name and password. 11. If using MAMP or XAMPP on a Mac: in your browser, go to localhost:8888/name-of-your-drupal-folder/install.php. If in XAMPP on a PC, you don't need the :8888. 12. You should see the starting point of the install process. Follow the prompts and your install will be done. If you see an error message - such as, Cannot Connect To Database - make sure you have followed all the steps, including using "local" or "localhost" in the user settings. If you use "any host", the install may fail, especially on a Mac. What does Drupal include? (Notes are primarily from Using Drupal, by Heather Berry and Angela Byron, O'Reilly Publishing. Second Edition. ) Flexible module system Modules are plug-ins that can modify and add features to a Drupal site. For almost any functional need, chances are good that either an existing module fits the need exactly or can be combined with other modules to fit the need, or that whatever existing code there is can get you a good chunk of the way there. Customizable theming system All output in Drupal is fully customizable, so you can bend the look and feel of your site to your will (or, more precisely, to your designer’s will). Extensible content creation You can define new types of content (blog, event, word of the day) on the fly, and even create custom fields for the different content types. Contributed modules can extend this even further by providing more kinds of fields and different ways to manipulate them. Innate search engine optimization Drupal offers out-of-the-box support for human-readable system URLs, and all of Drupal’s output is standards-compliant; both of these features make for search engine friendly websites. Role-based access permissions Custom roles and a plethora of permissions allow for fine-grained control over who can access what within the system. And existing modules can take this level of access control even further—down to the individual user level. Social publishing and collaboration tools Drupal has built-in support for tools such as group blogging, comments, forums, and customized user profiles. The addition of almost any other feature you can imagine—for instance, ratings, user groups, or moderation tools—is only a download away. Key Drupal Concepts Modules Just about everything in Drupal revolves around the concept of modules, which are files that contain PHP code and a set of functionalities that Drupal knows how to use. All of the administrative- and end-user-facing functionality in Drupal, from fundamental features such as ability to log in or create content to dynamic photo galleries and complex voting systems, all come from modules. Some examples of modules are the Contact module, which enables a site-wide contact form, and the User module, which handles user authentication and permission checking. In other CMS applications, modules are also referred to as plug-ins or extensions. There are two types of modules: “core” modules, which are included with Drupal itself, and “contributed” modules, which are provided by the Drupal community and can be separately downloaded and enabled. Apart from a few required core modules, all modules can be turned on or off depending on your website’s precise needs. Users The next building block of a Drupal website is the concept of users. On a simple brochure-ware website that will be updated by a single administrator and visited only by potential customers, you might create just a single user account for the administrator. On a community discussion site, you would set up Drupal to allow all of the individuals who use the site to sign up for the site and create their own user accounts as well. Every additional user can be assigned to configurable roles, like “editor,” or “VIP.” Each role can be given permissions to do different things on the website: visiting specific URLs, viewing particular kinds of content, posting on existing content, filling out a user profile, even creating more users and their permissions. By default, Drupal comes with two predefined locked roles: user and anonymous user. Anyone who creates a user account on the site is automatically assigned the “authenticated user” role, and any visitors who haven't yet created user accounts (or haven’t yet logged in with their username and password) have the “anonymous user” role. In addition Drupal provides a third predefined, but optional, role: administrator. Any user given the administrator role will automatically access to all permissions available on the site. Content (Nodes) Nodes are Drupal’s next building block, and one of the most important. An important part of planning any Drupal site is looking at your plans and deciding what specific kinds of content (referred to by Drupal as “content types”) you’ll be working with. In almost every case, each one will be a different kind of node. All nodes, regardless of the type of content they store, share a handful of basic properties: - An author (the user on your site who created the content) - A creation date - A title - Body content For example, a page containing your company’s privacy policy is a node. Blog entries on the site are nodes. Links to stories elsewhere on the web - those are nodes as well. In addition to nodes’ basic, common properties, all nodes can take advantage of built-in Drupal features, like flags that indicate whether they’re published or and settings to control how each type of node is displayed. Permissions to create and edit each type of node can also be assigned to different user roles;; for example, users with the “blogger” role could create “Blog entry” nodes, but only "administrator" or “editor” users could create “News” nodes. Drupal comes preconfigured with two types of nodes: Basic Page and Article. Basic page nodes don’t display any information about the author or the date on which they were posted. They’re well suited to content like “About Us” and “Terms of Service,” where the original author is irrelevant. Articles do display that information, are set to appear on the front page of the site whenever they’re posted, and allow the content creator to add tags to the content. The result is a blog-like list of the latest stories on the site. The Administrator can create other types of content, or nodes, to meet specific needs. For example, Announcements might be a type you would create to post "official" announcements. Also, certain modules allow the creation of specific node types. The Poll Module, which does come with Drupal core, allows the creation of polling questions, which show up as voting questions to users, and which can tally the results of user polling input. Additionally, other modules can add to nodes’ properties such as comments, ratings, file upload fields, and more. From the control panel, you can specify which types of nodes receive these features. Managing the Content Each individual node on your site gets its own URL. By default, this URL is something like http://www.example.com/node/1. These URLs can be turned into user friendly paths like http://www.example.com/about using Drupal’s built-in Path module. Every other content page on your site—topical overviews, recent news, and so on—is created by pulling up lists of nodes that match certain criteria and displaying them in different ways. Here are a few examples: The front page By default, the front page of a Drupal site is a blog-like overview of the 10 most recently posted stories. To build this, Drupal searches the pool of content for nodes with the “Published” flag set to true, and the “Promote to front page” flag set to true. In addition, it sorts the list so that nodes with the “Sticky” flag are always at the top; this feature is useful for hot news or announcements that every user should see. The Taxonomy module We mentioned earlier that plug-in modules can add new pieces of information to nodes, and that’s exactly what Taxonomy does. It allows the administrator of a site to set up categories of topics that nodes can be associated with when they’re created, as well as blog-style free-tagging keywords. You might use this module to create a predefined set of “Regions” for news stories to be filed under, as well as “Tags” for bloggers to enter manually when they post. The Taxonomy module calls all of these things “terms,” and provides a page for each descriptive term that’s used on the site. When a visitor views one of these pages, Drupal pulls up a list of all the nodes that were tagged with the term. The Blog module Drupal’s built-in Blog module implements a multiuser blogging system by doing just three things. - First, it adds a new node type called “Blog post.” - Second, it provides a listing page at http://www.example.com/blog that displays any nodes of type “Blog” that also have their “Published” flag set to true. (If a blog post has its “Published to front page” flag set to true, it will show up on the front page as well; Drupal never hides content on one page just because it appears on another.) -Third, it provides a custom page for each user on the site that displays only blog posts written by that user. http://www.example.com/blog/1, for example, would display all blog post nodes that are published and were written by User 1—the administrator. The important thing to remember is that almost all “pages” in Drupal are one of two things: a specific content node, or a list of nodes that share a particular set of properties. Types of Supporting Content In addition to content and listings of content, there are also various ways to supplement the content on the page. Two such types of supporting content included with Drupal core are comments and blocks. Comments are merely responses by a user to a piece of content, and exist only in relation to that content. Users may post comments to add their thoughts to the subject matter within a node. Comments can be expanded with contributed modules to have additional features such as ratings or file upload fields. Comments provide a large number of options to tweak: How they are displayed or sorted, whether anonymous users are allowed to or prevented from leaving comments, and contact details can be required or optional. Blocks are widgets that fit into areas such as the sidebars, footers, and headers of a Drupal site. They’re generally used to display helpful links or dynamic lists such as “Most popular content” or “Latest comments” and similar items. The users building block controls information about and access for your site’s visitors; nodes take center stage displaying content; and blocks help give a single piece of content some context in the structure of your site. Many times, blocks will display different content, depending on which user is currently logged in: a “Comments by your buddies” block, for example, might display a list of posts by users that the current visitor has added to their Buddies list. Each user who logs in will obviously see a different list. Additionally, blocks may be configured to show up only on certain pages, or to be hidden only on certain pages. Comments The core Comment module allows website visitors to post replies to the content within a node, which allows a discussion on the topic at hand directly with the author as well as with one another. Most content types have comments enabled by has commenting turned off initially. Navigation (Note that these are a starting point and you don't have to use them as you get more advanced.) -Main menu A menu provided for custom navigation needs, typically displayed very prominently in the site’s design. Major sections of the site such as “Home” and “About Us” tend to be placed in the Main menu. -User menu Displays links relevant to the current user, such as My account and Log out. Generally placed in the upper right corner. In the default configuration, these links will be printed twice: once for administrators in the Toolbar, and once for end-users. -Navigation A general menu that acts as the default “dumping ground” of links offered by new modules, when they are not strictly administrative tasks. For example, when enabling the Forum module, a "Forums" link to the forum listing page is added to the Navigation menu. Many modules offer links under the Navigation menu that are originally disabled, but can be optionally turned on. -Management Holds links to administration tasks, essentially duplicating the administrative toolbar at the top of the page, for sites that don't use the default Toolbar module. You can configure which menu to use for "Main menu" and "Secondary menu" at Structure→Menus→Settings tab (admin/structure/menu/settings). Under normal conditions, both of these menus are different (they default to "Main menu" and "User menu", respectively). However, if you set both Main and Secondary menu to the same value, this creates a sort of “drill-down” effect in which the top-level items are displayed in the main menu region, and any sub-items beneath the currently active main menu link are displayed dynamically in secondary region. The powerful Menu Block module generalizes this one-off feature, and allows the creation of additional "sub" menus, and provides a variety of other advanced configuration options. Blocks Blocks are smaller chunks of content that you can place in your pages. Examples of some default blocks provided are “Who’s online,” which shows a listing of users currently logged in; the “User login” block, which displays a login form to anonymous users; and “Recent comments,” which shows a list of the newest comments on the site. The Navigation bar in the sidebar, the “Powered by Drupal” text in the footer shown in Figure 2-12, and even the entire content area of the page are blocks! You can also make your own custom blocks: for example, you might create a block to display an announcement about an upcoming event. Blocks are placed within a region of a page. Examples of regions are “Sidebar first,” “Footer,” and “Content.” Region names, and exactly where they on a page, vary from theme to theme; some may define additional regions such as “Banner ad” or remove or change some of the default regions. Therefore, blocks be configured on a per-theme basis. In this process of creating a website, we will look at these modules. Notice that all but one is in "core" - that is, they come with Drupal, and while they may need to be enabled, they do not need to be downloaded. Node (core) Allows you to post content and create your own content types Comment (core) Allows users to create replies to node content User (core) Allows users to log in, as well as Drupal’s robust roles and permissions systems Block (core) Adds dynamic sidebars and other supplementary content Menu (core) Handles management of a Drupal website’s navigation Path (core) Allows entry of friendly URLs such as http://www.example.com/about rather than http://www.example.com/node/1. Module Filter (http://drupal.org/project/module_filter) Allows administrators to quickly filter down the list of modules by keyword Contact (core) A simple form that site visitors may use to send inquiries to website owners - Changing Adminstrative Settings The website is a simple one for a small organic grocery store. There will be one website administrator and two editors. They'll want to have a place where they can showcase weekly deals, highlight in-store events, or general goings-on in the community. Visitors to the site should be able to comment on these announcements, with anonymous visitors’ comments going into an approval queue first Administrative Interface In Drupal the website itself and administration tools to manage it are integrated together. In building out your site, you will frequently pop in and out of the administration section by clicking "edit" on a piece of content, or "configure" on a particular part of the page. The administrative interface of Drupal is split into the following sections: Dashboard While initially quite sparse, the Dashboard allows you to set up a custom administrative landing page for your content editors, to provide a "one-stop-shop" for all of the things they need to know, such as who are the recent users who've registered to the site, or comments that are awaiting approval. Content Creating, editing, and deleting content and comments can be done from the Content administration link. You can also manage workflow information, such as whether or not the content is published, or whether comments awaiting moderation are approved. Structure Configuration related to how your site is fundamentally built—for example, choosing what data you wish to capture in your content, and how you navigate to that content—is housed in the Structure section. Appearance This menu allows you to choose and configure themes, which control the look and feel of your site. People Managing the people who administer and visit your site, as well as what they're allowed to do, happens here. Modules Modules are a central construct in Drupal. Installing and enabling modules is how you add new features and change the existing behaviour of Drupal to meet your precise needs. Configuration The configuration section is where most modules will put their administration links. Configuration links are categorized under headings such as "User interface" and "Web services." Reports The reports section is useful for both keeping up with the maintenance as well as gaining insight as to how your audience interacts with your site. • The Status report offers a quick glimpse of your site's overall health and will warn you of configuration problems. • The Recent log entries report allows you to monitor site activity as it happens— errors, user activity, content notifications, and more will appear here. • The Available updates report will show whether your modules and themes are out of date, and also allows you to install updates from within the user interface. • A variety of "Top" reports (e.g. Top 'access denied' errors, Top search phrases) will show you where your users are running into the most errors, what your users are searching for the most, and if you're running the core Statistics module, the most popular content on your site. Help Help contains some basic instructions to help you get started, as well as a help page for each module you have installed. These pages explain both a general overview of what the module does, as well as some specific uses and how to perform them. Creating a Basic Page First, we’ll make a simple "About Us" page, to get the hang of Drupal's content creation and editing tools. 1. Go to Add content→Basic page (node/add/page) in either the "Navigation" block or the Shortcut bar. 2. Enter the page's Title, Body, and other settings provided in Table 2-1. Because this is a static page, we’ll also place it into our site's main navigation menu. And finally, we'll give the page a friendly path of http://example.com/about instead of http://example.com/node/1 by providing a "URL path alias." Table 2-1. About Us page values Setting Value Title: About Us Body: Our store has been providing organic food to the community since 1978. Come and see us at: 123 Main Street Home Town, MN Store hours: 12pm–12am Text format Filtered HTML (default) Menu settings • Provide a menu link Checked • Menu link title About Us (default) • Description Learn more about Mom & Pop, Inc. • Parent item
(default) • Weight 0 (default) URL path settings:URL alias about Setting URL aliases by hand can be tedious. The Pathauto module, covered in Chapter 6, allows you to set up customized rules that automatically generate friendly URLs for all of your website content (http://example.com/content/about), users (http://example. com/user/admin), and more. Creating an Article Next, let's experiment with creating an Article—Drupal's other default content type. Unlike Basic page, which contain just a Title and Body field, Articles add the ability to also provide Tags (or keywords) and an Image on each post. Articles also have comments enabled, and automatically get posted to Drupal's default Home page in reverse chronological order, making them useful for things like announcements. So, let's announce the creation of our new website! The features described here for Basic page and Article are only their default behavior. It's possible to fully customize the capabilities of these or any other content type under the Structure→Content types (admin/ structure/types) administrative page. The next chapter will go into much detail about doing this sort of customization; for now, we'll stick with the defaults. 1. Go to Add content→Article (node/add/article) in either the "Navigation" block or the Shortcut bar. 2. Enter the article's Title, Body, and other settings provided in Table 2-1 and click Save. This time, we're not going to supply a menu item, because this announcement will appear on our home page so we'll have a way to navigate to it. We'll also enter a "Summary" for this post, so that the home page shows a small bit of text but requires clicking "Read more" to read the article's entire contents. Table 2-2. Welcome announcement values Setting Value Title: Welcome to our new website! Tags: (leave blank for now; we'll talk about tags in Chapter 3) Summary: (click "Edit summary" link next to the "Body" field to expose) Read all about our new website and what it means for you! Body: Welcome to our new website, powered by Drupal! Don't know what Drupal is? Don't worry; we don't either. :) The important thing is that we can now update our website much faster and more often than before! We'll be posting about in-store promotions, great upcoming deals, and general community events. Stay tuned for further announcements! Text format: Filtered HTML (default) Managing Site Navigation Great! We now have some simple content on the site and our navigation menu is starting to come together. However, there’s something a little funny going on: our tabs in the top left-hand corner are displayed in alphabetical order, which puts “About Us” before “Home.” It would make a lot more sense for “Home” to come first, so let’s fix that by reordering the items listed in the menu. 1. Go to Structure→Menus (admin/structure/menu) in the toolbar, and click "list links" next to Main menu (admin/structure/menu/manage/main-menu). 2. Using the handles on the left side, drag the Home item above the About Us item. You'll see a notice that the changes will not be saved until the form is submitted. 3. Make sure to click “Save configuration” to save your menu settings. Configuring Blocks Next, let’s start to play around a bit with blocks on the site. We don't need that "Powered by Drupal” block in the footer. So let’s remove it. Additionally, want to be able to show off the latest weekly deal prominently on the home page, which is the perfect use for a custom block. 1. Begin by navigating to the block administration page at Structure→Blocks (admin/structure/block). Here, you will see a list of all of the available regions. 2. Let's start by removing the "Powered by Drupal" block. Scroll down the page the "Footer" region, click the handle next to the "Powered by Drupal" block, and move it down to the "Disabled" region. 3. The yellow background and asterisk indicate that the changes are not yet saved. Click the "Save blocks" button to remove the block from the footer. 4. Next, let's look into that weekly deals block. We'll start by finding a suitable place for this announcement. Click the "Demonstrate block regions" link at the top of the page to see a preview of available block regions and their styling. Notice the "Featured" region displayed along the top, with a grey background. That should help it stand out from the rest of the page. Click "Exit block region demonstration" in the upper left to return back to the block administration page. 5. Next, we need to add our own custom block. Click the “Add block” link at the top of the page (admin/structure/block/add). 6. Enter the settings from Table 2-3. Use the “Page-specific visibility settings” to ensure that the block shows up only on the home page. We can also add the block to the "Featured" region right from this form. Table 2-3. Settings for weekly deals block Field Value Block-specific settings Block description: Weekly deals Block title: This week’s deals! Block body: New this week: Oranges! Only 42 cents each. Yum! Text format: Filtered HTML (default) Region settings Bartik: Featured Seven: None (default) Visibility settings: Pages Show block on specific pages: Only the listed pages Pages 7. After saving this form with the “Save block” button, you’ll return to the main block administration page. Click the "X" in the upper-right of the Overlay to return back to your site, which should now look as pictured in Figure 2-23.