QQ Creating a Patch File

In this exercise, you create a patch file against the beginning_drupal module. NOTE In order to complete this exercise, you will need to have the diff and patch applications installed. Mac OS X and Linux include these utilities, but Windows does not. Windows users can download and install diffutils from Alternatively the Cygwin shell can be used http cygwin.org. Follow these steps to create the patch 1. Create a copy of beginning_drupal.module, and name the new file beginning_drupal.module....

Chapter Cpn

Theming is the term used to describe the act of modifying a site's layout, color scheme, and possibly its HTML structure. 2. Where are new themes installed New themes are installed either at sites all themes, which will make them available to all sites in a multi-site installation, or sites lt site.name gt themes for example sites example.com themes . 3. Is it possible for a theme to not have HTML files Of course Drupal's core and contributed modules include sets of suggested HTML provided by...

Test Driven Development

You have been introduced to testing after writing your module because this book is designed for users new to Drupal and or new to development. Many developers have shifted to writing their tests before writing their code to ensure that the code is written correctly and to reduce bugs during development. This is known as test-driven development TDD . Before you write your first test take some time to explore Drupal's testing environment. Follow these steps to test your website using SimpleTest...

How It Works Awg

Spaces are allowed punctuation is not allowed except for periods, hyphens, apostrophes, and underscores. A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address s not made public and will only be used if you wish to receive a new password 01 wish to receive certain news or notifications by e-mail. Password strength 11 1 Passwords match yes Provide a password for the new account in both fields, 9f authenticated user administrator Notify user of new...

Understanding CVS Tags

After completing the last two exercises you may be curious about how Drupal uses versioning and how that corresponds to CVS. Drupal's core, themes, and modules each have official stable and development unstable versions, as well as major and minor versions. Consider the releases shown in Figure 18-1. You can see that this project has two official releases one for Drupal 6 6.x-2.3 and one for Drupal 5 5.x-1.6 . The version for Drupal 7 is still in development, as evidenced by the name...

Triggers And Actions

Although introduced much earlier, actions became a part of the core beginning with Drupal 6. Actions introduced the first robots into Drupal as a way of segmenting tasks so that they could be automated. Some of the actions included with Drupal's core include publishing and un-publishing a node, promoting and demoting a page to the frontpage, sending an e-mail, and many others. It is often a user who performs these activities, but because technically speaking, these activities are actions, they...

baseurl

This setting directs Drupal to always return the same base URL, regardless of how the user accessed the site. For example, if your site is hosted at http mysite.local drupal7 and is also hosted at http mynewsite.local, you can force Drupal to always return http mynewsite.local. Set this variable like the following baseurl http mynewsite.local This can be a great setting if you are transitioning a website to a new URL but be aware that Drupal does not send a 301 redirect with this setting. A 301...

Summary Scm

Drupal's community is a worldwide collage of language and culture backgrounds. These folks work together to build Drupal sites all over the world for audiences who speak nearly every language. Drupal 7 has a unique ability to translate not only its own interface, but also the interface of other modules you add over time. The built-in Locale module provides this interface translation. If you couple the Locale module with the contributed Localization module and visit http localize. drupal.org,...

Advanced Views

This chapter covers Views' immense and complex Graphical User Interface GUI . But Views also contains an even more powerful Application Programming Interface API that allows module developers to extend and enhance views. Because it is an advanced developer topic, this book does not cover the API. You can learn more about the API on the Views project page at http drupal.org project views. There is one topic, however, that even non-developers use from time to time embedding a view. Embedding a...

Advanced Search Settings

During the first Try It Out exercise, you set a permission that allowed authenticated users to use the Advanced Search features available at http localhost search and shown in Figure 9-5. The Advanced Search options allow a user to limit their search to a specific content type, use negative queries, or search for whole phrases. Keep in mind that conducting a search using the Advanced Search settings takes longer and utilizes more system resources, which is why you did not grant the permission...

Style Sheets

The stylesheets property provides two important functions. The first is the ability to specify different style sheets for different W3C media types such as a web browser, handheld device, or a printer. Consider the following example stylesheets all style.css stylesheets handheld handheld.css stylesheets print print.css This would render the following output lt link type text css rel stylesheet media all lt link type text css rel stylesheet media handheld href sites all yourtheme handheld.css gt...

Working with Actions

Actions are a core and central part of Drupal therefore, they are always available for use. You can view the complete set of actions or create new actions at Administer C gt Configuration C gt System C gt Actions. Figure 10-1 shows the default actions available. Note that each action has a type shown on the left this is typically the name of the module that performs the action. All modules have the ability to provide custom actions, so your site may contain additional actions not listed here....

Style Settings

After completing the preceding exercise, you most likely discovered an ugly block that looked like your site's frontpage crammed into the left sidebar, which was probably not what you were expecting. The left side of Figure 11-21 shows what your default block would look like if left as is. This section introduces Style Settings, which will transform your block into the much cleaner and summarized block shown on the right side of Figure 11-21. You will also learn how to create lists, tables,...

Credits

VICE PRESIDENT AND EXECUTIVE GROUP PUBLISHER VICE PRESIDENT AND EXECUTIVE PUBLISHER Jeff Lytle, Happenstance Type-O-Rama PROOFREADER

Storing Data In A Custom Table

At this point your module is providing nearly all of the necessary functionality. A configurable set of keywords is being restricted from the comments and the module has its own permission set. It's missing just one last feature the ability to track the users attempting to post these comments. In the next exercise you will track the users attempting to post offending comments by storing a count of their attempts. You will create a custom table, store data in the database, and create an...

Field Types Type of Data to Store

Although it would be easy to create all fields as simple text fields it is not very user friendly. A field type allows you to control what the user can or should enter. For example, if you add a field that asks a user for the sales price you most likely want them to enter it numerically i.e., 40 and not forty . Specific field types are often created for items such as postal codes, phone numbers, addresses, etc. to verify that the data entered is correct before it is saved and presented on the...

A Bit Of Terminology

The term internationalization is often used as a very broad and ambiguous term referring to numerous actions, all of which relate to modifying Drupal's core language English and its settings. Internationalization generally relates to two activities localizing and translating. Here are a few terms to help you decipher the lingo of internationalization Localizing Refers to the modification of the user interface to the local standards. This may include translating the text used for menus, buttons,...

Arguments

Arguments are a powerful and often underutilized part of Views. An argument is a variable that alters the results returned by a view in other words, it is a dynamically configured filter. For example, Figure 11-32 shows the argument jredding being used with the gallery URL the view . This argument will filter the results so that only photos from jredding are shown. Photos byjredding 3 Beginning DrupaE In this section, you'll modify your gallery so that the photographer's name appears below...

Robotically Promote Content to the Frontpage

Using the Rules module, you will create a rule that automatically promotes a node to the frontpage when a member of the Editors role posts a comment on the node. The following prerequisite steps were performed in the exercises earlier in this chapter Create a new role named Editors. Create a user account named Editor and add this account to the Editors role. Before proceeding download, install, and enable the Rules module, which also includes the Rules administration UI module. You can download...

Writing Your Own SimpleTest

Writing a test for your module to ensure that its bug free not only instills confidence in your module and code-writing ability, it also saves you development time by pinpointing where the problems are and reducing your ongoing maintenance. Tests help you write the module correctly the first time. Tests are stored in a separate .test file contained with the module. Testing consists of two types of tests unit tests and functional tests. Unit tests focus on the code itself, or code testing code....

Forcing Sessions to Expire

Although the default behavior of Drupal is to let a session last quite a long time, it can be desirable to override this behavior and force a session to expire earlier. You may choose to do this because you are running a secure application that must verify your user's identities or because of server limitations when dealing with millions of users and their associated sessions. Each session is stored in the Drupal's database session table, and a million sessions on a slow database server can...

Configuring the Aggregation Settings

Drupal's defaults are sane if you will be aggregating only a few RSS feeds but should be adjusted if you aggregate a significant number. Click on Settings at the top of the Feed Aggregator main page to adjust the defaults shown in Figure 6-56. The most important setting on this page is Discard items older than. When Drupal retrieves data it is placed within your site's database. The more feeds and content you aggregate combined with the length of time you keep them will increase the size of...

QQ Adding Taxonomy to Your Content

In this exercise you will add a Food Type category to your Article content type allowing you to categorize the article as about Asian or Middle Eastern food. This exercise will walk you through three basic steps 1 adding a vocabulary, 2 adding terms to the vocabulary, 3 adding a taxonomy field to the Article content type. Step 1 - Adding a Food Type Vocabulary 1. Navigate to Taxonomy by clicking Structure in the top administration bar then Taxonomy. 2. Click Add Vocabulary at the top of the...

Content Moderation

Due to the complexity of moderation and no single moderation standard, Drupal does not provide a moderation system out of the box. This should not be seen as a fault but rather a testament to Drupal's flexibility. Moderation can be done in several ways here are just a few. Triggers and actions Covered in Chapter 10, triggers and actions can send your moderator an e-mail when new content is posted alerting them to review the content. A simple default unpublished state that the moderator flips to...

Making Your View Accessible via a Tab

A great trick when using Views is to place your custom view alongside existing tab or menu structures. Take a look at Figure 11-47 and notice that the selection Comment Review selection is available alongside Drupal's default administration pages. Also consider Figure 11-48, which shows a custom tab on the user's profile page that links them to a custom view with a listing of all of their comments. ft Dashboard Content Structure Appearance People Modules Configuration Reports Help Heflo...

Approving Accounts in Moderation

When administrator approval is required for user accounts, Drupal sets the newly created user account to blocked status. You will have to manually unblock the account. Follow the next exercise to learn how to do this. In this exercise, you unblock newly created user accounts. Please complete the previous exercise before continuing, if you have not already done so. 1. Log out of your website. Create a new user account by clicking Create New Account under the User Login block as shown in User...

Allowing Rich Text Comments

Comments are initially constrained to a small set of HTML through the use of a Text format, by default this is set to filtered HTML as discussed in Chapter 4. You can allow more HTML by simply modifying the filtered HMTL text format or assigning a new default text format at Administer O Configuration O Text formats under Content Authoring . You can enable wiki-code, BBCode or other syntax easily by installing the appropriate text format module. Find these and other similar modules here http...

hookuser

Just like hook_node_ , prior to Drupal 7 hook_user was a single hook that has been branched out to multiple hooks, each beginning with hook_user. These hooks allow you to act on the creation, updating, or deletion of a user account as well as the modification of a user's profile, a user's roles, and more. You first start by choosing the operation on which you want to act. Two examples are hook_user_ presave, used to act upon or add additional information during initial account creation, and...

Widgets Form Element

A widget is used for the display of the field during node creation or editing and is specific to the field type. For example, a list field type contains two widgets checkboxes radio buttons or a select list. The results of each are the same, that is the user can choose one or one or more options, but the presentation of the field differs. Returning to your Gossip content type consider if you added a field for the Gossip's truthiness allowing users to select one or more options that describe how...

Avoid the Buffet

Kahlid Bahey, a seasoned Drupal developer, once wrote a blog post entitled open buffet binge that fairly accurately describes how some newcomers approach Drupal. He explained that when presented with a large list of useful and free modules, these folks gorged themselves by downloading everything they thought would be useful. There are two problems with this approach. The first problem pertains to your server. In a very simplistic explanation, each module uses a small portion of your server's...

Enabling Anonymous Users to Use the Contact Form

After you complete this exercise, anonymous users will be able to use the Contact form to send you an e-mail. 1. Log into your website as an Administrator. Navigate to Configuration, and then click Permissions as shown in Figure 3-21. 2. Grant the anonymous user access to the site-wide contact form by checking the corresponding box in the Anonymous User column, as shown in Figure 3-22. 3. Click the Save Permissions button at the bottom of the screen. How It Works When the Contact module was...

Custom Module Settings

Drupal is designed for rapid module development and does much of the work of saving your module's custom settings for you. Custom module settings are implemented by using hook_menu to tell Drupal where your module's configuration page is located. You then provide a settings form with the use of the Forms API FAPI and Drupal will do the rest. You do not need to create custom database tables to store simple configuration settings. The following exercise demonstrates how to do this. Add a Custom...

AllViews Permissions

These permissions control access to all views. You can configure the following all-views permissions at Configuration C gt Permissions Administer Views This permission grants access to create, edit, and delete every view on the system. Needless to say, this is a very sensitive permission and should only be granted to trusted users. Access All Views The name of this permission is slightly misleading. It allows users to bypass per-view permissions in order to see every view unrestricted. This...

Indexing Your Content

Indexing your content could also be called making your site's search engine work. If you perform a search after completing the previous exercise, you won't get any results this is because your site has not been indexed yet. Indexing occurs automatically when your site runs cron discussed in Chapter 3, Your First Drupal Website . You can see the status of your site's index, as shown in Figure 9-2, by navigating to Configuration C gt Search Settings. You can either wait for your site to run cron,...

Triggers Actions Workflow and Rules

WHAT YOU WILL LEARN IN THIS CHAPTER gt Use triggers and actions in such a way that you are notified when a new user signs up on the site gt Create an editorial review and approval workflow for your site's content gt Automatically promote content to the frontpage when a select group of users create or comment on it gt Automatically demote content from the frontpage after a set amount of time has passed v 4 WARNING At the time of writing Workflow and Rules were not updated to Drupal 7. This...

iniset

PHP settings can be modified within Drupal so that they are specific to the Drupal website. The default settings look something like the following ini_set 'session.cache_limiter', 'none' ini_set 'session.cookie_lifetime', 2000000 Two of the most useful settings aren't listed in settings.php the memory limit and error reporting. Drupal requires a bare-minimum of 16MB, but a default PHP installation is often set at only 8MB. If a site does not have enough memory, it will return a blank white...

Preflight Checklist

WHAT YOU WILL LEARN IN THIS CHAPTER gt Using a basic checklist for site maintenance, users, Search Engine Optimization SEO , performance, and disaster recovery to cover all your bases before going live gt Setting up and optimizing SEO for your site gt The importance of clean URLs and URL aliases gt An introduction to Google Analytics, and installing the module to monitor your site's activities gt Configuring your dashboard You are nearing the end of your Drupal journey. In the previous...

The Need for Speed

If you find that your site needs better performance than Drupal's core provides, look into using one of the following modules. Boost with large numbers of anonymous users can see a very significant performance boost with this module. The module is simple to install and easy to configure. Memcache with large numbers of logged-in authenticated users can increase performance by caching the requests made to the database through the use of a third-party caching mechanism called memcached. The...

Theme registry Mjv

admin_block_content Array, 6 elements authorIze messa g e Array, 4 elements authorize_report Array, 4 elements block admin display form Array, 9 elements template String, 7 characters comment path String, 34 characters themes garland type String, 12 characters themeenglne theme path Siring, 24 characters themes garland render element String, 8 characters elements theme paths Array, 2 elements preprocess functions Array, 5 elements 0 String, 19 characters template preprocess Callback...

Log into Your Offline Website

1. Manually navigate your browser to http localhost user or http localhost q user if you site is not using clean URLs. 2. Log in with an administrator account. How It Works Drupal maintenance mode is designed to restrict your users from adding new content such that you have perform maintenance on the site. Once a site is set to offline, administrators will stayed logged in and can perform all functions on the site. Non-administrators will be presented with the maintenance mode screen. NOTE The...

Custom Administration Pages With Views

When your site begins to grow and you find yourself with thousands, tens of thousands or, lucky you, hundreds of thousands of users, you might find that the built-in user management interface does not provide you with enough options. For example, you may want a page that displays the users that have logged in within the past X days, or a listing of all users with an e-mail address from a certain domain. The marketing department may want an up-to-date report on the number of users within a...

Template Suggestions 1

Now let's take a look at providing additional template suggestions. Using the same preprocess function, you can return a variable named template_file as follows function variables 'weather' Sunny if variables 'weather' Sunny variables 'template_file' 'page-sunny' If the weather is indeed sunny, then the template file page-sunny.tpl.php would be used instead of page.tpl.php. Of course, page-sunny.tpl.php must exist. You can provide a range of suggestions by adding as follows function variables...

Content Ranking

A better title for this section might be How to Define What's Relevant to Your Users. Content ranking allows you to modify the order in which results are returned during a search process, and help direct Drupal to what is relevant to your users. Opposite of most ordering in Drupal, a higher number means higher relevancy. The example shown in Figure 9-7 would cause content promoted to the frontpage to be returned higher in the search results than other content with a high number of user...

Analyzing Your Site With Google

Few web statistics tracking systems are as user-friendly and versatile as Google Analytics. It enables you to view a wide range of data about traffic to your site, including the top content of the day or month, where your visitors are from, which search engines and sites send the most traffic, and much Analyzing Your Site with Google 411 more. Google Analytics also support something called goals, which allow you to set a target such as a 50-percent increase of traffic to your shopping cart and...

Summary Wsi

Theming in Drupal can be a very complex process and, at first glance, daunting. However, taking your time to understand how all the pieces go together will help you become a Drupal theming ninja in no time. This chapter should have helped you discover that Drupal has a very flexible architecture that allows you to mold and manipulate it to meet your design and creative ideas. Your theme has full creative control over the final output sent to your visitors. Theming is about making your site look...

Exposed Filters

An exposed filter is a Views filter that can be modified by the user in real time without the user modifying the underlying view. Consider Figure 11-40, which shows an example of a custom Comment Moderation page. The filters at the top of the page are modifiable by any user with permission to see the view. Similis Roto Usitas Nibh Velit Inure Exposed filters are a great way to create custom administration pages such as the Comment page shown in Figure 11-40. In the next few exercises, you'll...

Time Zones When Creating Content

When you post content on your site, the date and time is based on your account setting. If you are a frequent traveler this may not be the correct time zone for your posting. In order to be reflective of the actual time you posted, you can either adjust your account's setting before writing the article or modify the recorded time manually. Users with the Administer nodes permission can modify the time zone of any post within the Authoring information of the node as shown in Figure 4-8....

Translating Your Content

The second half of creating a multilingual site is to translate your site's content the Articles and Pages you have added to the site. If you will be a running a monolingual site, there is no reason to add content translation, because you can simply submit all of your information in that language. You translate your site's content using Drupal's core Content Translation module. This module provides a method to translate your site's content and a method to link a piece of content to multiple...

Permission Handling

Implementing permissions in Drupal sounds intimidating but is in fact quite simple. There are only two steps to implementing custom permissions in Drupal 1. Declare your permission s with hook_permission. The second point cannot be understated. It is your responsibility to check that a user has the appropriate permission before you perform a secure action. You can use user_access 'permission name' to determine if a user has the appropriate permission. Drupal will automatically traverse the user...

Writing Your Own Filter

In Chapter 15, Custom Modules you'll learn how to write your own custom module. To jump start that process and get you excited take a look at how simple it is to write your own custom module. The Drupal API Application Programming Interface provides the function hook_filter_ info. Using this function, your module can tell Drupal how you will be filtering the text. function bd_chp4_filter_filter_info 'title' gt t 'Beginning Drupal Chapter 4 sample filter' 'description' gt t 'A very basic...