In the first part of this Drupal Features guide, you learned why Features is a vital tool for Drupal site builders and developers. We then created a new Feature, which contained a Todo list content type. In this part, you will create a View to display the todo list in a block and add the View to the Feature by recreating it. Views are not the only thing you might add to a feature module. You can add a whole range of components, such as image presets, context and strongarm (for variables) to an existing feature.
Create the View
If you don't already have the Views module installed, go ahead and install and enable it (you need to enable both Views and View UI modules).
Use the following details for the view: Name: todotoday_list
- Create a page: leave ticked
- Title: What shall I do today?
- Format: Table
- Content: Title (label: Task)
- Content: Status (label: Status)
- Content: Due Date (label: Due date)
![Adding a Drupal view filter](/assets/img/view_filter.png)
Figure 5-9: View filter
- Filter: Content: Published (Yes)
- Content: Type (=Task)
- Content: Status (Exposed, label: Status)
- Sort Criteria
- Content: Due date
- Sort ascending. Rearrange and move to the top.
The final View settings:
Figure 1: View settings
Go to /todotoday-list and you will see the todo list, with a filter for the Status field. By default, both New and Started are already selected, as this was set in the Exposed Filter settings above.
Figure 2: View todo list
Add Block display
It would be handy to have a block that can be added to a region such as a sidebar, so that as we move around the site, we always know what we need to do today.
Add a new Block display.
Figure 3: Adding Block display
Add Status field filter
Add a filter for the Status field and set “Is not one of: Done”. You do not want to see Tasks that you have already completed. Make sure it is set for this block (override), as we do not want to affect the page display in this view.
Figure 4: View filter
Add block to region
Add the block to the desired region in /admin/structure/block, and you should see something like this:
Figure 5: Todo list block
You have built the view via configuration, so it currently lives only in the database. You need to export this as code and add it to our module. Luckily Features makes this very easy.
Recreate the Feature
Now it is time to recreate the Feature in the Features UI.
Go to Structure -> Features and click on Recreate next to Todotoday.
You need to add the view that you just created. To do that, you can click on the select menu under Edit components. Then click on Views: views_view. You should see todotoday_list (todotoday_list) available as an option, so select it. The view will then be added to the feature.
Figure 6: Features UI
Now you need to download the feature and move the files into sites/all/modules/custom/todotoday.
And that is all there is to it.
In this post, you created a View for the Todo List and added it to an existing Feature module. You can recreate a Feature any time you want to add a new component to it. This ensures that your additions are always exported to code and your feature module is always up to date.
In the next tutorial, I will walk you through how to update and revert a feature. If you are not on the mailing list, jump on to ensure you don't miss it!
If you would like to learn more about creating features modules and how to take them to the next level with custom code, grab a copy of Master Drupal Module Development.