In this video you'll learn how to use api.drupal.org the canonical source for information about Drupal's hooks, APIs, and code documentation in order to find out information about implementing a particular hook, making use of a particular function or library of functions, and even gaining a better understanding of some of the big picture concepts behind Drupal's code and APIs.
This video walks through the handy devel module from http://drupal.org/project/devel and demonstrates the tools it provides for debugging, inspecting and analyzing the code and SQL queries happening on your site. In this video you'll also learn about some of the helper functions built into the devel module that make it simpler to inspect the large nested arrays that you'll commonly come across when writing code for Drupal.
You may not have heard of the function dsm() before now. It is a legacy function and dpm() is the newer name. The two functions are identical since dsm() is just a wrapper for dpm().
The idea is that dsm() was a poor name for the function, it's short for drupal set message, but what was later decided that drupal print (as in print_r) message was better.
The difference between those two and kpr() is that dpm() does a permissions check to make sure the current user has permission to view devel's output, and then puts the krumo'd variable dump into the message queue via drupal_set_message(). This means that dpm() will work and let you see the output even if you're redirected. Great for debugging forms. kpr() just krumo's and dumps the value right here, right now. No permission check, no regard for where the content is being spit out.
In this video Joe Shindelar provides a quick overview of the minimum set of tools you'll need in order to get started with module development. Some kind of web server to host your development site on, an editor that allows you to edit PHP files (preferably one with syntax highlighting), a MySQL client, and Drush. Learn about how these essential tools fit in the module developers tool belt and then download and install a bare bones copy of Drupal to start tinkering with.
"There's a module for that."
You've probably heard this before. Many times you can find a module that provides the functionality you need — or at least pretty close to what you need. Drupal's contributed module projects number in the thousands, but what if there isn't a module for your use case? You just might need to build a module for that.
In this series, you will learn about the tools and resources available to Drupal developers, including where to find documentation and what APIs are available to you, both on drupal.org and api.drupal.org. We'll take a look at the Devel module and learn how to use it to inspect the variables, objects, arrays and other things at work under the hood of Drupal 7.
You'll build several different modules that explore and interact with Drupal's various systems and API, including:
- Form API
- Menu system
- Hooks
- Render API
- Theme system
- Database API
Over the course of this series you'll be able to:
- Describe the anatomy of a module
- Implement common hooks
- Write more secure code
- Interact with Drupal's menu system
- Create and alter forms
- Peform CRUD operations on a database
This series starts with the basics and moves you step-by-step to more advanced concepts. Even if you are quite comfortable with PHP but are struggling to understand how to appropriately interact with Drupal 7's API, the lessons in this series can help you develop "The Drupal Way."
Additional resources
This screencast introduces the awesome Views Bulk Operations (VBO) module, that can be used to perform actions on objects listed with Views. The screencast covers:
- How to add VBO fields to your views, to allow actions
- That these fields are displayed as check boxes (or possibly radio buttons) in your view
- That each VBO field is tied to one type of data in the view (such as nodes, node revisions or users)
- That some VBO actions have configuration pages
Additional resources
Views Bulk Operations (VBO) guide (Drupal.org)
This screencast shows how to repeat scheduled events – in this case sending repeated reminders to users who have not logged in for a month. The screencast covers:
- How to set up a component for scheduling (as seen before)
- The point of re-using an ID for scheduled tasks, to avoid duplicate reminders
- The trick of finding a good triggering event for scheduling (which is not always easy)
- The trick of having a component schedule itself upon completion, thereby repeating the scheduling
- How to delete scheduled tasks, and why that may be a good idea
Additional resources
Rules guide (Drupal.org)
This screencast shows how to use fields when scheduling Rules components. In the example we are also using the Flag module, to allow people to sign up for reminder e-mails 24 hours before an event starts. The screencast covers:
- Using flags to load user lists in Rules
- Scheduling a rules component from a triggered rule
- Some words about rescheduling the evaluation if the event date should change
- Using conditions to make fields available in Rules configuration
- Using a date field to set evaluation time
- Adding an offset to the evaluation (-1 day)
- Verifying the configuration by executing the action set manually
Note: It would have been smarter to use the “Before saving content” event for this rule – to make it act on both new nodes and updates of existing ones. If combined with a check to see that the event is in the future, you would actually have pretty good notification system!
Additional resources
Rules guide (Drupal.org)
This screencast shows how to start using Rules Scheduler. It does this by mimicking the Comment Closer module – closing the comments on articles two weeks after they are created. The screencast covers:
- Rules Scheduler needs components – you can only schedule prepared components
- Components can be scheduled as actions, for example from reaction rules
- The evaluation time for scheduled tasks is set with strtotime(), which means that you can use highly flexible expressions
- You can also use data selection, combined with offsets if you want to
- Every scheduled task should have a unique task ID, or it will replace existing tasks
- Scheduled tasks are displayed under the Schedule tab on the Rules admin pages
- You can delete tasks manually if you want to
- You can schedule tasks manually, without the need of reaction rules
- It is sometimes useful to execute rule components manually, to see that the scheduled tasks will work as expected
Additional resources
Rules guide (Drupal.org)
This screencast shows how to go about debugging Rules configuration. It covers:
- Enabling the debug information in Rules, showing rules evaluation.
- How to drill down into Rules’ debug messages.
- That most (or all) times, it is your configuration and not the Rules engine that has the bug.
- That the most common bug is condition that evaluates in an unexpected way.
- How to see how long time rules execution takes – and why/when this may be important.
- How to use the debugging action in Rules, to inspect the data in Rules.
Additional resources
Rules guide (Drupal.org)
This screencast shows how to work with export and import of Rules configuration, in particular using the Features module. It covers:
- Why you should use the Features and Strongarm modules.
- How to export Rules configuration with Features.
- How to import Feature-exported Rules configuration to a site.
- What reverting rules configuration means, and how to do it from Rules or Features.
- How to (eventually) export Rules configuration manually, and some words about the high readability in the Rules export code.
- How to import manually exported Rules configuration, including some available options/tweaks.
- Why configuration management is an important issue for Drupal.
For more information and tutorials on the Features module, check out the Drupal Deployment with Features & Drush Series.
Additional resources
Rules guide (Drupal.org)
This screencast presents a way to automatically create the article promotions used in the previous screencast. Topics covered are:
- Using the after new content has been created event, which does provide content NID
- Working with rule set components.
- Creating new entities with Rules.
- Setting field values in new entities – even complex fields like images.
- Force-saving entities, for example to get node IDs.
Additional resources
Rules guide (Drupal.org)
This screencast presents a way to help manage article promotions, separate content types used for promoting articles, providing more flexibility than standard teasers. The screencast shows how to have promotion nodes being published, unpublished and deleted in sync with the articles they belong to. Topics covered are:
- Reacting on the node deletion event.
- Using fetch entity by property to load a list of all relevant promotion nodes.
- How to have the loaded list unlimited in length.
- Using the delete entity action.
- How to call rule components from a reaction rule.
- Why it might be a good idea to have actions in separate components when acting on node updates.
- Cloning rule components.
- Publishing and unpublishing nodes.
Additional resources
Rules guide (Drupal.org)
This screencast shows how to set up Rules to allow comment writers to be notified when replies are posted to their comments. It covers:
- Adding a checkbox to the comment form, turning on or off reply notifications
- Sending e-mails to the comment author when new comments are posted
- Not sending e-mails when replying to own comments
- Some words about checking “entity has field” on the correct entity
Additional resources
Rules guide (Drupal.org)
This screencast shows how to set up Rules to allow node authors to – optionally – receive e-mail notifications when comments are posted to his or her content. It covers:
- Adding a checkbox to user accounts, turning on or off comment notification
- Sending e-mails to a node author when new comments are posted
- Not sending e-mails to the author if he/she was the one writing the comment
Additional resources
Rules guide (Drupal.org)
Login Redirects
FreeThis screencast shows how to set up Rules to mimick parts of the Login Destination module. It covers:
- How to redirect administrators to the content admin page on login
- How to redirect non-adminsitrators to the front page on login
- That you need the “force redirect” option when redirecting on login (yes, really!)
- Some words about utilizing user permissions instead of user roles for conditions
Additional resources
Rules guide (Drupal.org)
Components
FreeWhy creating Rules components? Here is why!
- You can reuse and simplify configuration
- You can export each component individually
- You can use rules components to perform conditions from within actions
- You can execute components manually for easier debugging (or just for the sake of executing their actions)
An important aspect of components is that they have variables – parameters that must be sent to the component when executing it.
Additional resources
Rules guide (Drupal.org)
Combining Conditions
FreeThis screencast explains how to use AND and OR groups in Rules to configure more complex conditions. This is demonstrated by creating a rule that notifies administrators when content is promoted to front page using an OR group. (The same procedure can be used to create an AND group.)
The screencast covers:
- How to combine conditions
- How to create an OR group
- Some advice about the order of conditions
- How to delete reaction rules
- Why you shouldn’t use the “send e-mail to all users in a role” action
- Why it might be useful to have messages printed out when configuring complex rules
Additional resources
Rules guide (Drupal.org)
This tutorial guides you on a quick safari through the actions, conditions and events provided by Rules core. It covers:
- A quick look at some actions provided by Rules
- A quick look at conditions provided by Rules
- A quick look at events provided by Rules
- Some words about data objects being provided to Rules by the triggering events
- Some words about multiple events in one rule limiting the available data (rather than expanding)
Additional resources
Rules guide (Drupal.org)
This tutorial presents data types and the data selection method for input in Rules. This is the most important difference between Rules 1 (D6) and Rules 2 (D7).
- How to use data selection to explore available data and drill down to selected properties
- Using the data comparison condition
- Using the set a data value action
- That Rules recognizes different types of data, and verifies when necessary
- That Rules knows that not all data is writable, and verifies when necessary
- How to create composite tokens, extending the tokens listed in the replacement patterns
- Making field values accessible to Rules
- Using reference fields to access new data, such as tags on an article or nodes in a node reference field
Additional resources
Rules guide (Drupal.org)