Continuing on our work with preprocess functions, we look at how to add a new variable for our template files to use. We also see how to change the output based on whether the user is logged in or not, and how to add a variable to the t() function.
Additional resources
In this chapter, we'll walk through some of the best practices for filling out a stock Drupal site so that you can start to have some dummy content generated by different users and tagged with different taxonomy tags. We'll step through creating content with the devel generate module, and then do some other site preparation tasks such as creating some menu items and adding a shortcut link to the performance page so that you can quickly access the clear cache button.
Additional resources
In this video we will look at overriding a theme function instead of working with the template files. We will be modifying the breadcrumb using theme_breadcrumb(). to do this we'll use the Theme Developer module to help us find what we're looking for, and then we'll walk through how to override.
Additional resources
Theme Developer module (Drupal.org)
960 Robots
Provides a overview presentation for how Drupal's menu system takes care of incoming requests via the index.php. Then it walks through the process of implementing a simple module that hooks into Drupal's menu system at the path of /magic.
It then executes a page callback function of menu_magic_basic(),
which outputs some simple markup text.
Additional resources
In this video we will see how we can create our own preprocess function for a theme function (not just templates). We're going to use this to display the user's full name on the site wherever the the username would normally appear. We start by creating a full name field, and then show how to get this working on our site.
Additional resources
In this video we will look at how to add CSS and JavaScript to our site using drupal_add_css()
and drupal_add_js()
. We will also show using these functions to conditionally add the CSS and JavaScript, within our page preprocess function.
Additional resources
In this video we'll see how we can create our own template suggestions. We'll do this in our node preprocess function to create a new node template that will be used depending on the day of the week.
Additional resources
This video goes through some of the strategies for translating a design into a Drupal theme. We talk about the two approaches of adding the HTML to an existing Drupal theme template vs. inserting dynamic variables into the HTML provided by our designer. Throughout this video, we're going to be assuming that our designer has delivered the full HTML, CSS and JavaScript to us, and we'll be adding in the dynamic variables. In this process we start to look at the design and start to break it up into it's component Drupal parts and start to strategize for how to build out the site and implement the design..
Additional resources
This screencast gives miscellaneous tips when writing Rules plugins, such as:
- Some words on declaring new data types for Rules
- How to restrict access to plugins
- How to form alter plugin configuration forms
- How to provide additional form validation
- How to use the "base" property to provide a non-default callback function
- How to invoke events programmatically with all arguments in a single array
- How to use drupal_static() to share variables/values with other parts of Drupal
This screencast shows how to add parameters to your actions, for example to allow site builders to select which user object an action should work with.
This screencast shows:
- How to declare that an action provides new data objects to Rules
- How to actually send the created data to Rules
- How to save parameters that are manipulated by the action (but not created by it)
The example used creates an action that returns the number of hits in a selected view.
This screencast shows how to:
- Use text as an input parameter for an action
- Provide your action configuration with a customized select list
- Restrict input for a parameter to "direct input" (and not data selection)
This screencast shows how to create a condition plugin for Rules:
- How to declare new conditions for Rules
- How to provide the condition callbacks with parameters to act on
- The big similarities and the few differences between actions and conditions
In the example, a condition is built to check which view type a provided view has.
This screencast shows how to:
- Invoke a Rules event
- Send parameter data to a Rules event
This is shown by an event triggered every time a view is being rendered, sending the name of the view as a parameter.
This screencast shows how to:
- Declare a Rules event
- Declare the data provided by the event
- Use that data in a rule
The example used creates an event "View is being rendered", passing along information about which view is being used.
This video shows the basic syntax for creating form dependencies with the states system. For a more information about the states system, then be sure to check out JavaScript form dependencies with the States System.
Note: There is a typo in the code used in this video. The function form_fun_states_form()
is missing a parameter, and should be: function form_fun_states_form($form, &$form_state)
.
When writing code for the web it is very important that you pay attention to security. Drupal provides many tools to help you out and in this presentation we'll look at what those are and how to make sure you use them properly.
Additional resources
In this chapter we learn how to get data out of the database and display it. The example walks through writing a module that creates a page that displays how many nodes are published and unpublished for each content type in our site. We use the db_select() function to accomplish this.
In this chapter we learn about changing the definition of a database table after it has already been installed. This example expands on the previous chapters by adding a new field to the table to collect the date a user last visited a node. We learn more about hook_update_N() as well as db_add_field().
In this chapter we learn other ways to interact with our database beyond the simple db_select() query from the earlier video. This example walks through writing a module that that saves and displays data about how many times a user has visited a specific page. We learn about db_select(), db_insert(), db_update(), db_merge(), db_delete() and introduce the concept of "get and set" helper functions.