Friday, March 30, 2012

Creating a New Vocabulary for Drupal Taxonomy

It is important to note that content can belong to several vocabularies at once. Also vocabulary relations can be modified dynamically as new content or new vocabularies are added. This saves the trouble to manually update the relationships each time.

The taxonomy module in Drupal allows multiple lists of categories for classification. It offers the possibility of creating thesauri (terms with horizontal relationships) and taxonomies (terms with hierarchical relationships). Basically, the taxonomy deals with a hierarchy of information and the thesaurus deals with relationships between terms. Taxonomy is what affects how exactly the content is organized.

Settings for the taxonomy module can be found at Administer >> Content Management >> Taxonomy.

With a fresh Drupal installation no vocabularies will be shown in the list.

You can add a new vocabulary using the "Add vocabulary" button.

In the next video we will show you how to create a new vocabulary.

Custom Search Module for Drupal



The Drupal core provides a Search module which is great for many sites. However, it doesn't provide some of the more sophisticated features that some sites need. The Custom Search module is a good alternative if you want more control over what gets searched, who gets to search, and what results you see.

The Custom Search module adds layers of control and sophistication to the core search module. It's easy to install and understand, and will give you more control over the search functions on your site. It also integrates with other search modules and APIs.



The core search function and the Custom Search module


tutuploadsmedia_1332978557735.png



The basic elements of the core search module are:

  • A block for front-end display. There is very little configuration available for this block. I've named this one "Core Search Block" to make it easy to distinguish from the customized one We'll be creating.

  • Advanced search is available on search results page. If a user clicks Advanced Search on the results page, a form opens up so you can refine your search. (When using the Garland Template).


This gives you a sophisticated search, but little control over how it's implemented throughout the site. A good way to expand on this is to add the Custom Search Module. Here's a summary of the added options.

Basic options:

  • Select which content type(s) to search,

  • Select which specific module search to use (node, help, user or any module that implements search),

  • advanced criteria


Advanced options:

  • change the default search box label,

  • add a default text in the search box,

  • add advanced search criteria,

  • change the default submit button text,

  • use an image instead of the submit button,

  • change the order of all the elements,

  • include some elements in a popup block,

  • add a filter to the results page,

  • show/hide basic and/or advanced search in the results page,

  • show/hide meta data in the results page,

  • multiple search paths





Step 1. Download and install the module







Step 2. Enable the module and its sub-modules


tutuploadsmedia_1332974776069.png



There are three included sub-modules:

  • Custom Search Taxonomy: taxonomy options for the search block.

  • Custom Search Blocks: provides additional search blocks, with different settings.

  • Custom Search Internationalization.





Step 3. Set Permissions for users and administrators


tutuploadsmedia_1332974833304.png



  • The confirmation message will have a link to the permissions. Click it to go directly to the permission settings.





tutuploadsmedia_1332975091365.png



  • Set user and admin permissions for two modules. I wanted everyone to be able to search so I gave anonymous users and authenticated users permissions by checking the boxes

  • You have four sets of permissions to set.

    • Custom Search

      • Admin

      • User



    • Custom Search Blocks

      • Admin

      • User









Step 4. Configure the module


tutuploadsmedia_1332975243521.png



  • Return to the Modules page and click Configure. You can also get to the configuration screen by going to Configure > Custom Search








tutuploadsmedia_1332975841984.png



  • When you land on the configuration page the selected tab will be highlighted. You will be going through all the tabs to complete the full configuration. So when you complete the first page, choose another tab and continue

  • I'm not going to go through every single configuration step. The choices are easy. If you have a need to create refined searches, they will make sense to you. If not, trial and error is the best way to get familiar with them. In this demo I'm going to enable everything.

  • There is one section that may need a little explanation - the Search Blocks tab:





tutuploadsmedia_1332981680985.png



  • Select the number of blocks. One of the great things about this module is that every block can have it's own configuration settings. Suppose you wanted a block on the home page that searched the entire site, but not the forum. On the forum page you want a block that only searches the forum. In that case you would create two blocks. If you wanted anonymous users to be able to search just some forum topics, and registered users to have more option, you would create 3 blocks, and control which one shows by who's logged in.

  • I'm just going to create one for this demo. Once you decide on this, add blocks to your site.

  • Be sure to save before moving on.





Step 5. Add blocks to your site


tutuploadsmedia_1332982028297.png



  • Go to Structure > Blocks.





Step 6. Assign blocks to regions


tutuploadsmedia_1332976654551.png



  • The custom search blocks you created will be visible and numbered.

  • Choose the regions for the blocks.





tutuploadsmedia_1332982219714.png



  • The new block is added.

  • The original block created by the core is still there. It's default label is Search Form. I can't think of a reason why you would want both of them on the same page unless you're writing a tutorial, so you can remove the original if you want.

  • Be sure to Save Blocks before you try any configuration.





Step 7. Customize the blocks from the front end


tutuploadsmedia_1332982785885.png



Here are both blocks, the original core search block and the one I just added. Compare the look of the Core one with the first image. You'll see that some custom features have been added. The first picture just shows an entry field and a search button. Now we can search tags and forums. This is because the new module makes those capabilities available to all the modules.

It also makes customization very simple. When you are viewing the module from the front end, mouse over the title and you will see an icon that looks like a cog from a gear.




tutuploadsmedia_1332983164241.png



This will give you access to the configuration for this particular module. It makes it much simpler if you are going to have multiple search boxes with different types of search. You can define each one while you are on it's page. It saves time and prevents mistakes.




Step 8. Configure Visibility


tutuploadsmedia_1332983345582.png



  • Clicking Configure will allow you to change the visibility and normal block function.





tutuploadsmedia_1332977044916.png



  • Clicking Custom Search configuration will give you access to define the search box itself.





Step 9. Configure each block to have custom features


tutuploadsmedia_1332983579145.png



From here you can configure what's include and what type of search you want.




Result


tutuploadsmedia_1332983702278.png



Above you can see what the original search block looks like after I've configured some additional elements to show. This will allow you to present a highly customized search experience to your the public and authorized users.


Multiple Categories with the Drupal Contact Module

The Drupal Contact module is often replaced by the Webform module. However, it can be useful in some situations. For example, image that you have different departments and you want each of them to get a different contact form on your Drupal website. If you're willing to keep it simple, you can do everything you need with the core Contact module and won't have to install anything else.



It all depends on knowing how to create categories and blocks.



Step 1. Make sure the Contact module is enabled


tutuploadstutuploadsStep_1._Make_sure_the_Contact_module_is_enabled.png



  1. Click Modules

  2. Click Save configuration.

  3. Click Configure next to Contact.





Step 2. Add and edit categories.


tutuploadstutuploadsStep_2._Add_and_edit_categories..png



Click Add category to add a new one.

There is a default category called Website feedback that you can use as well, but we are showing you how to add extra ones. You can edit the default category later if you need to.




Step 3. Configure the category


tutuploadstutuploadsStep_3._Configure_the_category..png



  1. Give the category a name.

  2. Specify the Recipients

  3. Create an Auto-reply message.

  4. Set Selected. Yes means it will be the default contact form. Since this is a new category, you probably want this to be No. You can only have one default.*

  5. Be sure to click the Save button.


*Selected: When a visitor clicks on the link to the contact form, the categories will show in a drop down list. Whichever one is chosen with a "Yes" will show automatically If you want your visitor to be forced to choose a category before submitting the form, make all of these fields "No"

Continue repeating the process until you have all the categories you want. A "category" can be a different department, a group or individual.




Step 4. Enable the menu link


tutuploadstutuploadsStep_4._Enable_the_menu_link..png



Jump to the Menus administration page by clicking the blue link in the instruction paragraph. Alternatively you can get their via the admin menu and clicking Structure then Menus.




tutuploadstutuploadsAlternate_path_to_Menus.png



Step 5. List the links


tutuploadstutuploadsStep5._List_the_links.png



A Contact menu item (disabled by default) is added to the Navigation menu, which you can modify on the Menus administration page. Click list links next to Navigation.




Step 6. Enable the link


tutuploadstutuploadsStep_6._Enable_the_link.png



This menu link will go directly to the site-wide contact form. You will see a Contact menu item that is disabled. You can use this one as a guide for creating other menu links.




Step 7. Configure the link


tutuploadstutuploadsStep_7._Configure_the_link.png



  1. Edit the link title if needed.

  2. Enable the link so it appears on the menu.

  3. Choose the parent link if you want it to be different from the default "Navigation".





Step 8. Add a block with instructions for the user


tutuploadstutuploadsStep_8._Add_a_block_with_instructions_for_the_user.png



Go to Structure > Blocks.




Step 9. Add a block


tutuploadstutuploadsStep_9._Add_a_block..png



Step 10. Add the block information


tutuploadstutuploadsStep_10._Add_the_block_information..png



  1. Enter a Block Description. This will not be seen by the public.

  2. Enter a Block Title. This will be seen by the public.

  3. Write your instructions. This will also be visible to the public,


Scroll down the page.




Step 11. Set the visibility settings by assigning it to the Contacts page


tutuploadstutuploadsStep_11._Set_the_visibility_settings_by_assigning_it_to_t.png



  1. Choose "Only listed pages". The only page we want to have these instructions is the Contact page.

  2. Write "contact" in the text field.

  3. Save the block.


Specify pages by using their paths. Enter one path per line. The '*' character is a wild card. Example paths are blog for the blog page and blog/* for every personal blog.is the front page.

There are other parameters and settings on this page, but for the purpose of this tutorial we only need the basics.




Step 12. Enable the block


tutuploadstutuploadsStep_12._Enable_the_block.png



You will be returned to the Blocks page. You will find the block you added in the Disabled list with the title you created. To enable it, choose the position from the drop down box.




tutuploadstutuploadsmedia_1318376672850.png



Choose Help.

This box lists all of the regions available on the template you are using. On the Bartik template, the Help region is right where we want it. You may have a different idea or location on your website.




Step 13. Final configuration then save.


tutuploadstutuploadsStep_13._Final_configuration_then_save..png



As soon as you choose the region, the block title will now be visible at the top of the page that shows the enabled modules. The will be grouped by region, so this one will be under Help.

Remember to Save - scroll to the bottom of the page




tutuploadstutuploadsmedia_1318376971177.png



No changes will be saved until you click Save blocks.




Your result


tutuploadstutuploadsYour_result.png



If you followed all these steps you will have a contact form that looks something like this.

  1. There is a link on the menu to the form.

  2. The instructions are in the Help Region in a block you added.

  3. The correct email address shows. (this will change to the right one when the category is selected).

  4. There is a drop down list with the categories you created.




Getting Started With Drupal's Webform Module

Webform is the module for making forms and collecting information from users in Drupal.

After a submission, you can send users a thank-you email as well as sending a notification to administrators. Results can be exported into Excel or other spreadsheet applications. Webform also provides some basic statistical review and has an extensive API for expanding its features.



If you need to build a lot of customized, one-off forms, Webform is a more suitable solution than creating content types and using the CCK or Field modules.



Download the Webform Module


tutuploadsStep_1._Download_the_Webform_Module.png



Go to this url http://drupal.org/project/webform, and download the Webform Module.

There are some additional modules that add some functionality and make some operations easier. You can download the optional modules as well. To keep things simple, we'll use the basic module and show you how to create a simple survey of registered users.




tutuploadsmedia_1317090861314.png



Download the correct version. They may have changed since we wrote this, so be sure to check.




Install the Webform Module


tutuploadsStep_2._Install_the_Webform_Module.png



Enable the module


tutuploadsEnable_the_module.png



Go to the Modules page and scroll down to Webform and click the check box. Click Save configuration.




Access the form fields


tutuploadsAccess_the_form_fields.png



Go to Structure > Content types




tutuploadsmedia_1317093423174.png



Scroll down to Webform and look the right for the links to edit and manage fields and the display.




tutuploadsmedia_1317094660865.png



Click Edit

If you are familiar with CCK in Drupal 6, or Fields, which is now part of D7 core, you will see a familiar interface for adding and managing new fields.




tutuploadsmedia_1317095178845.png



This is not the place where you will be creating forms. Editing here is exactly the same as editing Fields in Content Types, which is a way to make fields available to this content type. From here you can edit fields, manage existing fields, the display and the comment functions by clicking on the appropriate tabs. But creating the actual form is done by adding content in the same way you would add an article.

You won't need to do much here but review all your choices and see if there is anything you feel you must change. The default values will work for the purposes of our demonstration. After you create your first form and understand the module you might want to revisit the configuration.

Now that the module is installed and the configuration is checked, you can begin building your survey form.




Create your first webform by adding it as content


tutuploadsStep_3._Create_your_first_webform_by_adding_it_as_content.png



Go to Content > Add Content > Webform

Don't get confused over Poll vs Webform. We are creating a form with various types of questions, not taking a Poll. Poll is another content type that is similar, but restricted to multiple selection fields and gathering the statistics on the responses. Webform is a form submission module, and collects the actual responses and stores them in a table for you to review. You can collect almost any type of data using Webform.




Create the basic form details


tutuploadsCreate_the_basic_entry_form_and_configure_the_same_as_any.png



Give it a title and make the decisions on all basic options. Save this with the save button at the bottom of the page.




Add form components


tutuploadsStep_4._Start_adding_form_components.png



Now you will see the controls for creating and editing the rest of the form elements. Start adding Form components on the WEBFORM tab.




tutuploadsStep_5._Make_a_pre-filled_username_field_using_a_Token.png



Give the component a label, choose textfield and then click Add.

We're surveying registered users, so we are going to automatically fill in their username. A name is basic text field, but we want our registered users to show up on the textfield, so we're going to make use of Tokens. Using Tokens is just an optional feature.




tutuploadsmedia_1317148972326.png



Enter the token %username in the Default value field.

This will pull the username from the data base and fill it in automatically.

If you don't see the TOKEN VALUES, you probably don't have the Token module installed. You only need Token if you want to fill in the default values taken from the data base. If this is going to be a blank field that the user will fill in when they visit the page, you can just leave the Default value blank. I used Token here to illustrate the possibilities available to you.

If you need the Token module you can download it here http://drupal.org/project/token

Scroll down the rest of the page and make any configuration selections you need then click Save Component at the very bottom of the page.




Create a "Select" field


tutuploadsStep_6._Create_your_first_Select_field.png



Fill in a new label and choose the Select options type from the drop down. Click Add and complete the options on the next screen




Create the list of options


tutuploadsStep_7._Create_the_list_of_options_for_the_user_to_choose.png



Go to Options and create Key Value Pairs. These pairs consist of a machine readable key and a plain language value separated by a "|" - This character is called a "pipe" and you can find it by holding shift while pressing the backslash key "\" key on most keyboards.

Key-value pairs MUST be specified as "safe_key|Some readable option". Use of only alphanumeric characters and underscores is recommended in keys. One option per line.

Save the Component.

Repeat this step for the flavor of the jelly and type of peanut butter.




tutuploads-_Default_choice_is_radio_buttons.png



When you are creating lists, the default type is radio buttons. If you want check boxes or a listbox the choices are farther down on the page. You can also set the field as mandatory or optional. If you click the "Multiple" check box at the top, the list will appear as check boxes. If you choose "Listbox" under DISPLAY you will have a drop down box. Selecting "Multiple" and "Listbox" will allow users to make multiple selections from a dropdown box.

When you create the Jelly type, add Other as a choice. Then add a text field so people can write in their suggestions.




Add a Text field


tutuploadsStep_8._Add_a_Text_field.png



You can add a text field, or a textarea. A text field is for short entries like names. A textarea will be a large area for entering more extensive written responses.

Other field types you might want to add for your purposes are an E-Mail field or Date Field. You can choose thees types from the dropdown "Type" box.




tutuploadsmedia_1317154370995.png



You can choose other field types from the Type drop down.




Add a preset field type


tutuploads-_Add_a_preset_field_type_-_an_added_feature_of_Webform.png



There is a convenience feature you may want to use. You can create pre-built option lists and add them to your form. The module comes with several default lists. Add one for States if you want to see how this looks on your form. Label it State and then choose the Select Options type and when you get to the next screen, make your selection.




tutuploadsmedia_1317151406971.png



Choose US States from the drop down.




Check your form


tutuploadsStep_9._Check_your_form_and_fine-tune_the_view..png



At this point your form will look similar to this. You can change the locations of the descriptions by clicking the WEBFORM tab and editing each item and making different configuration selections. Once you have the form ordered the way you like it and all the questions and fields correct. Go back to the WEBFORM tab EMAIL tab and set the EMAIL options.

You can use drag and drop to move form elements to different positions.




Configure the E-Mail options.


tutuploadsStep_10.__Configure_the_E-Mail_options..png



Go back to the WEBFORM tab and look for the E-mails sub-tab. Fill in an address and click Add.

Set the email address if you want to receive an email when the form is submitted. You can add multiples.




tutuploadsmedia_1317152290926.png



There are lots of choices to make. Be sure you check every one of them so they are correct for your form. Be sure to save the changes.




Configure the Form Settings


tutuploadsStep_11._Configure_the_Form_Settings.png



From the WEBFORM tab Click the Form Settings sub-tab at the top of the page. Check and modify settings as needed. Save your changes.

Now you can publish your form exactly like you would publish any other content item on your site. After you've had a chance to collect submissions, you will see the results when you are logged in as a user with the correct permissions.




tutuploadsmedia_1317152553413.png



Click Content > Find Content and select the form from the content list and you can find the results tab. This will allow you to see the collection of data you have as well as give you some simple analysis.