Chapter 9. Advanced Features and Modifications

We are going to start out by looking at a grab-bag of modules that showcase some of the more advanced or interesting features in Drupal in order to give you the opportunity to add that special something to your site. Whether it is new type of content, an advertising policy to generate revenue from traffic, or even a way of providing nice, dynamic content, you should find something to add value to your site in here.

Remember though, that if what is required is not available in the default distribution or in any of the modules, you are not totally out of luck. The chances are someone else in the community has had to do something similar before, and you should get a few helpful responses on the forums explaining at least some of what you need. If at some point you do manage to create something utterly fantastic, please give back to the community by sharing your work with others.

With that said, it is often important to be able to make your own additions to a site in order to get it just right. Accordingly, we will look at some interesting embellishments using code that is freely available on the Internet. Incorporating JavaScript and other small, working units of code (commonly known as widgets) is the perfect way to enhance your site without having to learn everything about programming first.

So, as far as new modules go, we will take a look at the following:

  • Flexinode
  • AdSense

The first module deals specifically with content, whereas the other one enables you to integrate your website with another online business, namely Google—hopefully to earn a bit of cash. By the end of this chapter, you will be an ace at using slightly more complex contributions.

We will also talk about some more advanced modifications to the interface. It's always fun to be able to do something out of the ordinary with your site, and working with your theme files, using HTML, PHP, and CSS, is great training for the Web in general and not just Drupal. The Advanced Site Modifications section here will hopefully give you some ideas for your own site as well as give you an idea of what's involved in implementing them.

One final thing to remember before we begin is that you must, must, must make backups of the whole site, including the database, from time to time (preferably each time you successfully add a new feature). Further, you should also back up each of the pages you are working on before you begin working with them. The topic of making backups is discussed in the Running your Website chapter, which follows this one—I mention this just in case you feel it is time to make a backup of what you have now before you begin fiddling around.

Flexinode

At some point along the way you might find that none of the current content types really fit the type of content you want to be able to deliver. If this is the case, then the Flexinode contribution might be just what you are looking for. As the module's description says:

Flexinode is a module that allows non-programmers to create new node types (flexible content types) in Drupal when their needs are modest. Users can define the fields in the node edit form for their content type, and can either view the nodes as presented by the module or modify the presentation in their theme.

In the case of the demo site, let's assume that we would like to build up a reservoir of vital statistics pages for endangered animals. In this case, we could go to the trouble of building a rough HTML template and use the page content type, inserting the relevant data into the various cells in our table. However, this would be a pain because if a variety of people were posting this type of information, then each of them would have to learn how to use this HTML template. Let's take a look how the Flexinode contribution can help out here.

Downloading and Installing Flexinode

This process should be quite familiar to you now; so we won't spend much time looking at it too closely.

Note

Flexinode at the time of writing is still being upgraded for version 4.7 compatibility—be careful and ensure that you obtain a suitable, stable version if you intend to use it on your live site.

Simply go to the Drupal website and download the correct version of the Flexinode module. Extract the files to the modules directory in your Drupal installation and then execute the .mysql script using something like the following command (remember to modify the file path to suit your individual system):

$ mysql udrupal p drupal < C:apache2triadhtdocsdrupalmodulesflexinodeflexinode.mysql

You will be prompted for a password and you can ensure that the relevant tables have been added by logging into the mysql command-line client and looking for the new Flexinode tables as shown in the following screenshot:

Downloading and Installing Flexinode

Notice that there are now three flexinode_ tables present in the drupal database. If you are not keen on using the command line, remember that you can use the visual interface provided by phpMyAdmin.

Funnily enough, this contribution comes with a bunch of contributions! What I mean is that there is extra functionality associated with Flexinode that is not enabled by default. Take a look at the extracted folder, flexinode, on your file system (under the modules directory). You will notice that there is a contrib folder present, and it contains a whole bunch of .inc files.

Each of these .inc files is responsible for providing the functionality associated with its namesake. For example, field_textarea.inc provides the code needed to include text areas into your content type, and so on. You'll also notice that there are a bunch of readme files available to help clarify what the corresponding .inc file does. For example, the README.colorpicker.txt file has this to say:

I am hoping that this will be useful in granting users control over the styles of their sites. I can imagine a flexinode with several color pickers, select boxes and check boxes that could be used to override the default styles of a theme for that particular user.

Ensure that you read the readme file for each and every .inc file you intend to enable, as you might be required to move files or even install other modules first. When you are ready, head on over to the modules section under administer in your browser and enable the Flexinode module before clicking Save configuration.

Creating a Custom Content Type

Under the administer section, navigate to content and you will notice that there are a couple of extra content-related tabs shown on this page that allow us to specify and work with our new content types. Clicking on the add content type tab will bring up a page like this:

Creating a Custom Content Type

Once that is Submitted, you will be taken to the content types page automatically, where you can now begin working with the newly created type as shown here:

Creating a Custom Content Type

From this point you can click on either of the two links presented at the top right of the content type's section (in this case, the section is entitled Animal Stats). The first link, edit content type, allows you to change any of the information you supplied when you created the content type—for example, you might wish to modify the name, description, or help text. The second option allows you to add some submission guidelines and configure the standard Workflow options as shown here:

Creating a Custom Content Type

These standard options have already been discussed in earlier chapters at some length and you really need to make your decisions based on how you intend this content type to be used. For our purposes, file attachments have been enabled (even though this is not visible in the screenshot) to allow evidence for any assertions made to be supplied with the post. Comments are also allowed in order for people to be able to collaboratively ensure that facts are correct and up to date.

With those two options out of the way, the really interesting and powerful part of the Flexinode module comes into play. The Field list provides us with the option to specify a number of different types of input, which are then bundled into the overall content type. Now, this can be slightly confusing to begin with because you need to keep in mind that you are specifying what is needed in order to make content, and not the actual content itself.

So, before you begin adding different fields all over the show, think carefully about what you want your special content type to do and how it should look. Once you have a clear idea of what it is you are creating, it will be a lot easier to go ahead and build it.

Adding Structure

Our Animal Stats pages should be informative and interesting, providing interested parties with a comprehensive and coherent body of knowledge that serves to fix an image of the animal, its profile, and its plight in the reader's mind. If one thinks about the types of elements that a page like this would need, something like the following would probably be suitable:

  • A paragraph or two introducing the animal
  • A picture of the animal
  • A summary of its current status
  • A map of its habitat
  • Contact information and/or links to more resources

With this in mind, we can turn to the field picker and see what it has to offer. Since the first thing we would like to show on the page is a paragraph, it makes sense to look for a text area to add to the top of the page. Selecting this option in the drop-down list shown on the content types page brings up the following form:

Adding Structure

Here the text area is set as a Required field because any user who wants to add an Animal Stats page must have a bit to say about the animal in the first place—a reasonable assumption! Making this a required field has the advantage that it is now a good idea to select Show in teaser (because we know that there will always be a bit of introductory text). This means that whenever anyone happens to browse through the Animal Stats pages, they can read the introductory paragraph in the teaser.

Next, a weight of 9 is assigned to this field because we know that in all likelihood this field will always be displayed at the very top of the page. In the same way, you can simply pick and choose the rest of the fields according to how the page is to be formatted. Each field comes with its own set of considerations that you will need to set depending on how the content page is to be used. As always, it is easy to come back and modify things if they aren't working just right.

Once all the fields have been correctly chosen and set into the correct part of the page, content producers can then use the page as they would any other node. That's it! All that's left to do is to ensure that the content works as it is supposed to and that it fulfils its intended role correctly. Since we have already discussed how to use other content types, we will go no further here.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175