In this course you will learn to build a Drupal custom module by completing short tasks and ultimately weave the tasks together to get a completed and fully functional module. Drupal 7 Module Development introduces you to module development by understanding the essential hooks and functions, building tables and querying the Drupal database, exploring module security, performance and how our module interacts with Drupal core and contributed modules. Each video walks you through essential Drupal functions and demonstrates how to use these functions in a module that we build hands-on together Drupal 7 Module Development starts by showing you how to set up your local development environment to support custom module development. You will learn how to use the best tools and configure them. Next you will learn to configure a Feeds importer to import content into your site that you will then leverage with your custom module and write a menu callback using hook_menu and hook_permissions. We will then look at the form API and write a hook_form_alter function and create a .install file and build a db schema function to create a table in our database Finally we create a block using our module and theme the block. We end the course by reviewing our module from a security and performance standpoint. From the local development to the review of security we build a custom module step-by-step throughout the course’s short videos.
Trevor's focus is on building Drupal-based web applications and portals for education, non-profit, and medical systems, and small business environments. He is interested in the best methods of integrating web services with Drupal sites, optimizing Drupal sites' performance, and using Drupal content types, Views, Panels, and other contributed modules to develop front-end interfaces that support data intensive websites.
He loves teaching people about Drupal and how to use this excellent open source content management framework.
We need to set up a local development environment for our Drupal programming. Install an Apache Web server locally with PHP and MySQL to support a Drupal 7 website.
Install a local integrated development environment that we'll use to code our custom Drupal module.
Set up a local Drupal 7 website install. Download Drupal 7.14 and install Drupal core.
Enable a few core Drupal 7 modules and inspect the /modules directory.
Learn how to set up folders to hold the contributed and custom Drupal module we'll be working on in this video series.
We've installed the Feeds module but we need to install the required and dependent modules so we can enable all of the Feeds suite of modules and configure a Feeds importer. We install the Ctools and Job Scheduler modules; as well as the Views, Devel and Feeds Tamper modules. We also load our Facebook page's RSS feed and get the RSS feed URL to use in our import process.
To import our RSS feed we need to clone an existing Feeds importer that handles XML and RSS feed parsing. Once the importer is created we can run our import by adding the RSS feed. The import will create nodes on our site using the Feeds Item content type.
Our PHP memory limit is at 32M but we'll need more memory to run the Feeds, Devel, and Feeds Tamper modules and run our import. We raise the memory limit to 96M. We also set up a tamper on our importer to change importer characters to specific apostrophes.
We need to be comfortable using PHP when we code our module so that we can point out some PHP resources for Drupal developers. We also look at some documentation on Drupal coding standards and inspect some contrib module code to see how these standards are applied.
The first custom module file we need to create is the .info file. We create the .info file and write some code into it. We also create a .module file. We then enable our new custom module.
We'll add some PHP code and comments to our module file and practice Drupal coding standards for commenting.
We need to know what functions are available to us when we write our module code so that we can review the api.drupal.org website.
We need to use the Devel module so we can have access to tools and utilities for Drupal developers.
How can we access specific content type field names and other data about our nodes? Using the Devel module enables us to inspect all of our page elements.
Now that we have our .info file and .module file created we need to start writing functions for our module. The first function we'll write is called hook_menu. This function will allow us to create an array(s) for each of our module's admin screen menu items. This way our module's users can configure the module via the Drupal admin interface.
If you do not see your hook_menu function working yet you need to flush the Drupal cache.
Now that we have a function in our module and the module is working, we need to add some permissions so our roles can use the module. We do this by writing a hook_permission function.
Now we need to add the admin.inc file to our module folder so we can start writing our menu callback functionality including the drupal_get_form function we added earlier to our .module file.
We have a blank admin.inc file that we need to add our admin_settings_form function to in order to build out the admin settings form for our module. We add the function to our admin.inc file and all form elements including a text field and checkbox series to it.
We've added a text field to our admin form. Now we expand our form by adding a checkbox series to allow for choosing the content types that our module will integrate with
We review how our module is setting and getting variables defined on our admin settings form.
Our text field needs a couple of validation handlers. We write these using hook_validate.
We need to allow our admins to choose specific nodes to show in the Facebook Feed Block. To do this we need to alter the content type edit form to add an admin fieldset for our checkbox.
We are collecting data via our hook_form_alter on our node edit form but currently we have no way to save the data we collect. We need to define our database schema and create our db tables for our module. First we need to create the .install file.
We need to add our hook_schema function to the .install file to define our first db table and schema for our module.
We need to add the schema for our hook_form_alter data. We add another schema array to our .install file.
Every time we add a schema function to our .install file we also need to uninstall and reinstall our module for the new schema to work. We also need to clear out all variables that we're setting when we uninstall our module. We do this by adding the hook_uninstall function.
We can add more functions to our .install file to manage the install and updating process.
We need to allow our module to modify a node when the user uses the hook_form_alter, so we need to add node hooks to allow us to modify the nodes that we have enabled for use with our module.
We continue to add node hooks to allow for updating and deleting any modifications that we've made to our nodes.
We still need to add our values set using our hook_form_alter to our database table. To do this we'll write some database wrapper functions that will query the db.
We add additional db queries to help with deleting data
We need to learn how to make our database query code as secure as possible and we look at some Drupal best practices for doing this.
We add a hook_block_info function that makes Drupal aware of our custom Facebook Feeds block.
We need to show content in our custom block so we add a hook_block_view function that will define our block contents.
We need to use a database query in order to display our Facebook posts inside the custom block.
Now that we have a block showing content we need to theme it with the custom style.
We need to write secure code throughout our module project life cycle so in this video we look at the various documentation that the Drupal API provides to help us write secure code.
We install and configure the Coder module to run automatic reviews of our contrib, core, and custom module code.
We need a system for running automatic tests of our custom module. We enable and configure the Testing module for this.
We now need to write a custom .test file and add this to our module.
We now need to enable our .test file via the Testing module and run our automated test.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.