Why to build a module instead of modifying source code, and how this video series works

. Why to build a module instead of modifying source code, and how this video series works

1. I'm Chris Shattuck and this is Welcome to Module Building. In this video we'll talk about the benefits of module building and we'll create a two minute module. If you look closely at the Drupal development learning curve you'll see that it is actually made of of a number of tiny steps. When you are on the curve it's kind of hard to tell exactly where you are, so consider this video a little "You Are Here" sticker.

2. By simply pressing the play button, you have said a lot about the steps you have taken already. For example, you know what a module is and you either suspect or you know that to get the functionality that you are looking for, you need to build a module of your own. But why do you need a module? I mean, why not simply download Drupal and start tweaking the code directly? It is open source after all.

3. By doing so, couldn't you sidestep a lot of the time that it takes to learn the layers and API's of Drupal and get what you need done more quickly? I'm sure you already know the answer to this, but just in case you jumped over a few of those learning curve steps along the way, let me fill you in on just what you get by wrapping up the code in a module instead. So if Drupal is a nuclear power plant, then adding modification to the source code is a lot like trying to power your vacuum by plugging it directly into the reactor. First of all, as far as I know, nuclear reactors don't have that kind of interface for supplying power to household appliances.

4. And secondly if you try to plug it in anyway, you are likely to cause a giant explosion and kill a lot of people. This metaphor might seem a little extreme but it is surprisingly on point. Just as electrical power becomes useful only when it is channelled through an outlet of some kind, the power of Drupal is channelled through its API's.

5. And the more you monkey with the inner workings of Drupal, the more likely it is to melt down. Next, working with a modified code base really kills the joy of upgrading Drupal. Upgrading should be a pleasure.

6. I mean, you are absorbing all these free bug fixes, improved security and added functionality for free. And not only should this be celebrated but regular upgrading is an essential requirement for a lot of my projects. With a modified code base though, instead of just dropping in the new files and replacing the old ones, you instead need to carefully extract and reapply all of your modifications to the new version.

7. And if your changes aren't well documented, it is easy to lose something along the way. It's even possible that you would find yourself avoiding upgrades all together and once the bit rot sets in after a few upgrade cycles you could actually find yourself in a position to completely abandon or simply rebuild your project. So upgradability is critical but is is only part of the module story.

8. Imagine for a moment they you have made a fantastic modification directly to the code base and you just have to have it on another project. How easy is it going to be to copy your changes over to that new project or what about copying it to 10 projects. And say 10 project are actually using your modifications and then you find a bug.

9. Well, the ability to share your code between projects and effectively push out bug fixes and updates can make a huge difference in productivity and quality, so if instead of modifying the source code directly, you wrap up your modification in a module, everything is in one place. And there is a number of methods that exist for then distributing your code across different projects, either public ally or internally. Basically what modules give you is code portability.

10. There is one more big bonus that you get when building a module. Because there is typically a clear path forward when modifying the behaviour of Drupal or adding new functionality, it make module code fairly reliable. This reliability then lays a foundation of solid techniques and rules for working with other developers.

11. And it's solid enough that many developers find it is relatively easy to ramp up on a Drupal site that somebody has built. Plus in a few months when you review your own work, there is some clear structure there that help you navigate your code, even if you didn't have a chance to write good comments at the time. So by keeping your code in a module, you get the power of Drupal's API's.

12. You get upgradability, portability and reliability. When you really understand these benefits, the time and cost of learning how to build modules the right way, it is more than justified. It is actually a steal.

13. Given all of this you would think that it would be really hard to wrap your mind around something so powerful right? Well, yes and no, but mostly no. For example I'm about to show you how to build a module in just a couple minutes and that same module structure can then be used as a starting point for any other module that you need to build. And many of the concepts around module building are just like this.

14. They're easy to grasp and they are easy to implement. The tricky part is that there is a lot of concepts. So for example, there are over 250 functions that allow you to hook directly into Drupal to do anything from adding triggers and actions to altering the content of Drupal's search index.

15. There are also numerous API's that allow you to plug into forms, add new kinds of fields and work with files in the database and that's just to name a few. But if you find this daunting, there's a couple things that might help you out. First, what all this functionality means is that when you need to modify or extend Drupal there is probably a function or an API that will make your life a whole like easier and that's encouraging.

16. Secondly, many modules just touch on one or two of these features and that means you only need to know just what you need to know in order to get what you need. So it's ok to start small. Throughout the course of this video series, we are going to be spending some time working up the learning curve; step by step.

17. But We're also going to be spending time above the curve looking at what's behind us and at what lays ahead. We just spent a few minutes above the curve reviewing why putting your code in a module is a good idea and hopefully I have filled in a few gaps. Now we are going back to the ground level to take a few more steps up while we build a very simple module.
Drupal 7 Development Core Concepts

In our most popular collection, we build a strong foundation for developing in Drupal, covering the most commonly used APIs, building practical and interesting modules, and covering a tremendous amount of ground. Just a few of the topics we cover:

  • How to build and manipulate forms with the Form API
  • How to write jQuery to build a rich interface
  • How to programmatically manipulate content and user data
Video Library
21m 46sIntroduction
21m1. Welcome to BuildAModule
10h 36mBuild Your First Drupal 7 Web Site
36m1. Introduction to Our Project and Reviewing Mockups
35m2. How to Create and Edit Content
38m3. How to Work With Menus, Modules and Webform
41m4. How to Work With Content Types and Fields
37m5. How to Work With Pathauto and Introduction to Views
32m6. How to Add Fields to a View and Work With the Date Module
36m7. How to Fix Broken Views and Work With Taxonomy
35m8. How to use Term and Node Reference Fields
31m9. How to Work With Blocks and Permissions
31m10. Overview of Permissions and Text Formats
34m11. Configuring Text Formats and Setting Up a Wysiwyg
33m12. Working With Custom Blocks and Image Styles
34m13. How to Work With CSS
34m14. Troubleshooting Module Installation and Configuration
33m15. Updating Modules and Manipulating CSS
32m16. More CSS Updates and Troubleshooting Text Formats
31m17. How to Evaluate Modules and Install IMCE
44m18. How to configure IMCE and Wrap Up Our Project
6h 18mAdvanced Site Building in Drupal 7
23m1. Welcome to Advanced Site Building
30m2. How to Set Up Administration Tools to Speed Up Productivity
36m3. How to Configure Content Type Settings and Splitting Fields Between Types
41m4. How to Use Display Suite for Grouping Fields and Positioning Content
14m5. How to Use the Context Module for Positioning Content
42m6. How to Use Panels for Positioning Content
48m7. How to Import Content With Feeds
48m8. Advanced Views
30m9. Where Display Modules Overlap and URL Strategy
28m10. How to Work With User Fields and Import Users
34m11. Formatting a Blog Entry Page
12h 48mPHP Programming Basics
25m1. Series Introduction and Your First PHP Script
45m2. Working With Strings and Variables in PHP
31m3. How to Work With Arrays in PHP
40m4. Logic, Control Structures and Looping
1h5. Creating Custom Functions and Working With External Data
22m6. Troubleshooting errors and using operators
1h7. Working With Forms in PHP
1h8. Working With Sessions in PHP
1h9. Working With the (MySQL) Database
1h10. Working with CRUD functionality and our database
2h11. How to Build Your Own Content Management System and Understand Drupal Better
1h12. Generalizing Functionality and Object Oriented Programming Primer
12h 23mDrupal 7 Development Core Concepts
22m1. Welcome to Module Building
35m2. How to Build Module Scaffolding
1h3. How Hooks Work and How to Use Them
26m4. Overview of Coding Standards
51m5. Development Tips and Tricks
1h6. How to Build and Manipulate Forms with the Form API
1h7. How to Add and Manipulate Pages With the Menu System
52m8. How to Add to and Manipulate the Theme Layer
1h9. How to Work With the Database
54m10. How to Work With Users
1h11. How to Work With Nodes
2h12. How to Work With JavaScript and jQuery
9h 25mChange Management and Version Control
49m1. Installing Git and Working on the Command Line
58m2. Staging, Committing and Undoing in Git
34m3. Branching, Merging and Tagging in Git
1h4. Working With Remote Git Repositories
38m5. Deploying Releases, Features, and Fixes With Git
24m6. How to Version Control the Database
1h7. How To Version Control Site Configuration With Features
25m8. How To Manage Non-Exportable Configuration Changes
57m9. How to Override Shared Features and Modify Text
33m10. How to Upgrade Drupal and Patch Contributed Modules
37m11. How to Install Drupal, Manage Features and Perform Common Tasks Using Drush
31m12. How to Configure Drush and use Drush Make
37m13. How to Extend Drush and Other Useful Drush Tools
8h 1mDrupal Theming Essentials
1h1. Important Drupal Theming Concepts
1h2. How to Build and Modify a Drupal Theme or Sub-Theme
1h3. How to Build and Modify a Drupal Theme or Sub-Theme, Part 2
54m4. Theme CSS File Structure and Extended Drupal Theme Building
1h5. Template Files, Theme Function Overrides and Preprocessing Functions
1h6. How to Work With Drupal Theme Settings
8h 55mDrupal 6 Development and Tools
3h1. Essential Concepts
27m2. Working with jQuery and Javascript
1h3. Securing a Module
58m4. Testing and Debugging a Module
1h5. PHP and MySQL Basics
1h6. Using Komodo Edit as an IDE
2h 17mWorking with Files and the File API
39m1. How to Work With Files and the File API
1h2. How to Work With Files and the File API, Part 2
22m 53sAppendix
22m1. Mentored Training Resources
Double-tap to return to library

Loading...