Drupal 7 module development pdf


    Master Drupal 7 Module Development. 1. Lesson One - Introduction. In this section, you will be introduced to the core Drupal concepts required to develop. Module development tutorial: podmimokongist.ml DrupalCon Brussels. September 22, We're gonna learn module development by example Page 7. document titled Drupal 7 Module Development pdf - EBook Free Download is about Internet and Web Development.

    Author:OTHA EHLERT
    Language:English, Spanish, Arabic
    Genre:Children & Youth
    Published (Last):23.10.2015
    Distribution:Free* [*Register to download]
    Uploaded by: FELISHA

    60025 downloads 90763 Views 17.70MB PDF Size Report

    Drupal 7 Module Development Pdf

    Drupal Site Building & Introduction to Module Development. Training. (a) About 7. podmimokongist.ml – an excellent resource for support and http:// podmimokongist.ml 4. Pro Drupal. Pro Drupal 7 Development: Third Edition. Copyright © by How the Trigger Module Prepares the Context. .. Altering Menu Items from Other Modules. For PHP developers, this is the most practical book available if you want to start coding within Drupal. Every chapter has working code samples.

    My current position in the Drupal community is that of the Release Manager for the latest release of Drupal, version 7. Dries Buytaert and I work together with the core contributor team to help prioritize initiatives, encourage people attacking similar problems to work together, act as final quality assurance reviewers on patches, and ultimately commit changes to the project once they're ready. Drupal 7 represents a tremendous leap forward from previous releases. The core contributor team together took a very serious look at Drupal's limitations, from almost all angles. Usability testing research was done at several universities, highlighting long-standing problems with Drupal's user interface, and a usability team emerged to tackle the problems. Engineers collaborated together to identify and dissect severe API limitations that had plagued previous releases. The quality assurance team put tremendous efforts behind integrating automated testing into our development workflow, vastly improving our ability to refactor parts of the system. Drupal's designer community stepped up and became vocal about Drupal's limitations on the theming side that cause them to go flocking to other frameworks. An accessibility team emerged, not only pushing patches forward to improve Drupal's WCAG compliance, but also educating the members of the community about accessibility. Drupal 7 is a remarkable release for a number of reasons, but particularly for the diversity of the team involved in creating it. As a result of all of this effort, however, there is very little in Drupal 7 that hasn't changed over previous releases. The database abstraction layer has been completely re-written and is now based on the PHP Data Objects PDO library, which introduces a new object-oriented syntax to queries.

    Auto-update notification[ edit ] Drupal can automatically notify the administrator about new versions of modules, themes, or the Drupal core. Before updating it is highly recommended to take backup of core, modules, theme, files and database. If there is any error shown after update or new updates is not compatible with a module, then it can be quickly replaced by backup. There are several backup modules available in Drupal. On October 15, , a sql injection vulnerability was announced and update released.

    Database abstraction[ edit ] Prior to version 7, Drupal had functions that performed tasks related to databases, such as SQL query cleansing, multi-site table name prefixing, and generating proper SQL queries. Drupal 7 extends the data abstraction layer so that a programmer no longer needs to write SQL queries as text strings. Microsoft has written a database driver for their SQL Server. Windows development[ edit ] With Drupal 7's new database abstraction layer, and ability to run on the Windows web server IIS , it is now easier for Windows developers to participate in the Drupal community.

    A group on Drupal. The accessibility team is carrying on the work of identifying and resolving accessibility barriers and raising awareness within the community.

    There have been many improvements to both the visitor and administrator sides of Drupal, especially: Drag and drop functionality Improved color contrast and intensity Adding skip navigation to core themes Adding labels by default for input forms Fixing CSS display:none with consistent methods for hiding and exposing text on focus.

    The community also added an accessibility gate for core issues in Drupal 8. Drupal isolates core files from contributed modules and themes. More than just data The Drupal database does not store just application data or content , but also configuration, caches, metadata data about data , structural information, and sometimes even PHP code.

    While Drupal may not be database centric, it most certainly requires a database. During initialization, Drupal will connect to a database and retrieve certain configuration data. Later, as many of the core modules load, they too, contact the database to retrieve or update information. For most Drupal modules, the database is the location for data storage.

    Developing for Drupal 7 [ 16 ] The theme system The final component from our initial architectural diagram is the theme system. Drupal separates the look-and-feel components of the system from the rest of Drupal, and provides a programmatic way for theming data.

    The system for handling this is collectively called the theme system.

    Free Drupal 7 Module Development Books Download | PDFDrive

    Some of the theme system resides in the Drupal core libraries. This part is responsible for initializing themes and locating what theme functions and templates should be applied under certain circumstances. However, the majority of the theme code resides in themes and modules.

    A theme is a structured bundle of code like a module that provides tools for transforming raw data into formatted output. Sites use at least one theme to apply a consistent and custom look-and-feel to all of the pages on the site. However, Not all theme code resides inside of a theme. One of the distinct advantages offered by Drupal is the capability to define default theming inside modules, and then provide mechanisms by which the theme layer can selectively override those themes.

    In other words, a module might declare a rough layout for a component, but Drupal provides the structure for a theme developer to later modify the theme not the module to re-layout that component in a different way. If this all sounds conceptually difficult, don't worry. Chapter 3 and Chapter 4 of this book are dedicated to working with the theming system. Now that we've had a quick architectural overview, let's change perspectives and quickly peruse the major subsystems offered by Drupal.

    Drupal's major subsystems In the previous section we took a birds-eye view of Drupal's architecture. Now we are going to refine our perspective a bit. We are going to walk through the major subsystems that Drupal 7 has to offer.

    Themes The theme subsystem was introduced above, and since Chapter 3 and Chapter 4 will cover it, we won't dwell too much on it here. However, there are a few details that should be mentioned at the outset. Chapter 1 [ 17 ] The responsibility of theming a given piece of data is spread out over the Drupal core, the modules, and the applied theme itself.

    While we don't modify the Drupal core code, it is important for developers to be able to understand that both module code and theme code can manipulate the look and feel of data. In this book, our focus will be on the module perspective. We work primarily with theming functions and templates that are defined within the module. Typically, it is the best practice to work this way first—to ensure that every module has the ability to theme it's own data.

    Menus Drupal not only maintains content, but also details about how the site itself is organized. That is, it structures how content is related.

    The principle way that it does this is through the menu subsystem.

    Drupal Books

    This system provides APIs for generating, retrieving, and modifying elements that describe the site structure. Put in common parlance, it handles the system's navigational menus.

    Two menu systems? One source of frustration for developers new to Drupal is the fact that the application's front controller is called the menu router. However, this system is not identical to the menu subsystem. Its responsibility is to actually map the URLs to callback functions.

    We will return to the menu router in later chapters. Menus are hierarchical, that is, they have a tree-like structure. A menu item can have multiple children, each of which may have their own children, and so on. In this way, we can use the menu system to structure our site into sections and subsections. Nodes Perhaps the most important subsystem to know is the node system. In Drupal parlance, a node is a piece of text-based, publishable content.

    It can have numerous fields defined, but typically it has a title, a body, and various pieces of auxiliary data, such as timestamps, publishing state, and author identification. Nodes are content In computer science, the term "node" often has a special meaning.

    Drupal's own definition of node is distinct. It is not a point on a graph, but rather a piece of content. One might prefer to think of a Drupal node as a structured document. Developing for Drupal 7 [ 18 ] The node system is mostly implemented in the node module.

    This sophisticated module provides dozens of hooks, though means that many other modules can and do interact with the node module via hook implementations.

    Since nodes account for the content of the site, understanding the node system is an indispensable requirement for the Drupal developer. For that reason, we discuss aspects of the system throughout the book. Files In previous versions of Drupal, externally generated files notably images were not handled directly by Drupal itself.

    Instead, there were a plethora of modules available for working with files. This has changed in Drupal 7, which now has a file-centered subsystem. This means working with images, documents, and so on is now substantially easier. While Drupal has long had a sophisticated suite of tools for dealing with the filesystem in the files. Chapter 11 discusses this new API. Users Drupal is not designed to be merely a CMS, but also a platform for social media.

    Central to any concept of social media is a robust user system that can support not only administrative users, but also site members. Drupal offers a powerful user subsystem that allows developers to work with just about all aspects of user lifecycle, from what fields show up on a user profile, to what permissions at a fine-grained level users have, to what particular encryption scheme is used to encrypt the user's password.

    Drupal's user system even provides tools for making authentication and other aspects of user management pluggable. Modules provide, for instance, LDAP integration or authentication through many of the publicly available authentication services like OpenID. We discuss the user system, particularly the permissions aspects, throughout this book. Comments Perhaps the most common social media tool is comments. Drupal provides a subsystem that provides comment functionality for nodes and by extension, other data types.

    Chapter 1 [ 19 ] While one could imagine that comments are merely a type of node and, in fact, there are modules that do this , Drupal developers have chosen to implement comments as a separate type. The comment module contains the majority of the comment code.

    However, again, as with the node system, it provides numerous hooks, and thus many other modules interact with the comment system. Fields and entities In previous versions of Drupal, the node system was really the only system for creating structured pieces of textual content. Comments are too focused to be generally useful for extension. In order to extend node content beyond simple title and body fields, one needed to either write custom node types or use the Content Construction Kit CCK to build node types.

    However, Drupal 7 introduces two substantial subsystems that change this: The fields system brings most of CCK's functionality into core The entities system makes it possible to define other structured data types that are not nodes Already these new systems are making waves among Drupal developers, with the Drupal Commerce module leading the way in defining sophisticated entities that are not nodes. These two subsystems are new, important, and also complex.

    So we will cover them in detail in Chapter 6. This system provides a robust programmatic tool for defining, displaying, validating, and submitting forms. It takes much of the busy-work out of developing forms, and also adds a layer of security.

    FAPI is so integral to Drupal that we use it numerous times throughout the book. Installation Profiles More sophisticated Drupal use-cases may benefit from the ability to customize the installation process.

    Drupal provides an installation profile subsystem that can be leveraged to create a custom installer. Simple test Programmatically testing code is a well-established practice in the software development industry.

    In Drupal 7, it is a capability of the core Drupal distribution. Using the Simple Test framework, developers can now use functional and unit tests to validate their code. We employ testing throughout this book.

    In fact, we will write some of our first tests in Chapter 2. Blocks Along with the primary content, most web pages also have additional content displayed along the top, bottom, or sides of the page.

    Drupal's block subsystem handles the configuration and display of these units of content.

    Drupal 7 Module Development

    Most of this functionality is concentrated in the block module, and we will develop our first custom block in Chapter 2. Other subsystems In this section, we have provided some basic information on several high-profile subsystems. However, this list is not exhaustive. There are numerous others, and even some very important ones like Views that are not in core, but provided by third party modules.

    Some of these other subsystems will be introduced and discussed throughout this book. However, Drupal is a sophisticated system, and no book of a manageable length can go into all of the details. For that reason, we provide references throughout the book pointing developers to the appropriate resources on the web and elsewhere.

    Tools for developing Drupal code Drupal is a sophisticated platform, and from the glimpse above we can see already that there are numerous systems and structures to keep track of. In this section, we try to provide tools that simplify or streamline the development process. Chapter 1 [ 21 ] We assume that you have your own web server stack and your own PHP development tools.

    The authors of this book each use different editors, operating systems, and web server stacks, so we collectively understand that there are many good tools for developing PHP applications. And Drupal itself doesn't require anything special. If you are just getting started, you may want to look at Acquia Drupal http: While running a PHP debugger is certainly not necessary, you may find running Xdebug or the Zend Debugger to be useful.

    One of the authors of this book first learned how Drupal worked by stepping through an entire page load. Version control with Git and CVS Managing source code is a major part of any software development lifecycle.

    In this regard, Drupal 7 coincides with a major transition period for the Drupal community. However, Drupal has grown and the needs of the community have changed. Drupal is now moving to the Git distributed version control system. As we begin working with Drupal code, it will help to be able to have the tools necessary to work with Git.

    From command-line programs to full-featured desktop applications, there is no shortage of tools for this.

    The book's code and Git The authors of this book have been working with Git for some time one, in fact, is leading the CVS-to-Git conversion. We have done our best to make sure that all of the code contributions in this book are available from a Git repository. You can access the code for this book, view it online in a web browser, submit patches, or even branch your own copy and build your own tool.

    All the code is located at GitHub: Developing for Drupal 7 [ 22 ] The API site and coding standards A lot of background knowledge is required for writing good Drupal code. Of course, the aim of a book such as this is to provide that background knowledge. However, there are two reference resources that a burgeoning Drupal developer should have on-hand.

    The first is the official online API documentation. Just about every function in Drupal is documented using in-line code documentation. The Doxygen program is then used to extract that documentation and format it. You can access the full API documentation online at http: Best practices in software development include keeping code clean, consistent, and readable. One aspect of this is removing nuances in code formatting by following a fixed standard.

    This is particularly important on a platform like Drupal where thousands of developers all contribute to the code. Without coding standards, the code would become a cluttered mishmash of styles, and valuable development time would be spent merely deciphering code instead of working on it. The Drupal site has a manual on best practices http: All Drupal developers abide by these standards. While we have attempted to follow all of the coding guidelines in this book, we don't always explicitly point out what these standards are.

    So new developers are encouraged to peruse the coding standards given on the previously mentioned web address. Developer-oriented modules There are a few Drupal-specific development and administrative modules that deserve a mention. These are tools that are installed on the server to help simplify Drupal development. The developer module The Developer module provides several sophisticated tools designed to help developers create and debug Drupal code.

    For this, please refer to the following page: Functions used for dumping objects and arrays into formatted Drupal output Tools for analyzing database usage and performance A theme tool which indicates graphically which elements of a page were themed by which functions or templates A content generator for quickly populating your site with testing content Drush the Drupal shell Sometimes it is much easier to run some tasks with a single command in a console.

    Drush provides a command-line Drupal interface. It can be used to execute tasks with a few keystrokes at the console: Drush can help accomplish tasks like this. Coder The Coder module provides two big features: It can examine code for compliance against the Drupal coding standards It can automatically convert modules from one version of Drupal to another: Summary This chapter has been an overview of Drupal for developers.

    We saw what technologies Drupal uses. We looked at Drupal's architecture. We took a cursory glance at several prominent subsystems of Drupal's. We also got a feel of which developer-oriented tools are to be used while working with Drupal.

    Starting in the next chapter, we will be working with code. In fact, each of the subsequent chapters will focus on practical aspects of working with Drupal. Coming up next is an introduction to the block system, where we will write our first module.

    In the last chapter we surveyed Drupal's architecture advanced. We learned about the basic features and subsystems. We also saw some tools available for development. Now we are going to begin coding.

    Here are some of the important topics that we will cover in this chapter: Starting a new module Creating. Our goal: The module will use the Block Subsystem to add a new custom block. The block that we add will simply display a list of all of the currently enabled modules on our Drupal installation. The block subsystem was introduced in the previous chapter alongside other important Drupal subsystems.

    Create a new module folder and module files Work with the Block Subsystem Write automated tests using the SimpleTest framework included in Drupal We are going to proceed in that order for the sake of simplicity. One might object that, following agile development processes, we ought to begin by writing our tests. Agile software development is a particular methodology designed to help teams of developers effectively and efficiently build software.

    While Drupal itself has not been developed using an agile process, it does facilitate many of the agile practices. To learn more about agile, visit http: However, our goal here is not to exemplify a particular methodology, but to discover how to write modules. It is easier to learn module development by first writing the module, and then learn how to write unit tests. It is easier for two reasons: SimpleTest in spite of its name is the least simple part of this chapter.

    It will have double the code-weight of our actual module.

    We will need to become acquainted with the APIs we are going to use in development before we attempt to write tests that assume knowledge of those APIs. In regular module development, though, you may certainly choose to follow the TDD approach of writing tests first, and then writing the module.

    Let's now move on to the first step of creating a new module. Creating a new module Creating Drupal modules is easy. How easy? Easy enough that over 5, modules have been developed, and many Drupal developers are even PHP novices! In fact, the code in this chapter is an illustration of how easy module coding can be.

    We are going to create our first module with only one directory and two small files. However, there is one minor ambiguity that ought to be cleared up at the outset, a Drupal module has two names: A human-readable name: This name is designed to be read by humans, and should be one or a couple of words long.

    The words should be capitalized and separated by spaces. For example, one of the most popular Drupal modules has the human-readable name Views. A less-popular but perhaps more creatively named Drupal 6 module has the human-readable name Eldorado Superfly.

    A machine-readable name: This name is used internally by Drupal. It can be composed of lower-case and upper-case letters, digits, and the underscore character using upper-case letters in machine names is frowned upon, though.

    No other characters are allowed. By convention, the two names ought to be as similar as possible. Spaces should be replaced by underscores. Upper-case letters should generally be changed to lower-case. Because of the convention of similar naming, the two names can usually be used interchangeably, and most of the time it is not necessary to specifically declare which of the two names we are referring to.

    In cases where the difference needs to be made as in the next section , the authors will be careful to make it. Where does our module go? One of the less intuitive aspects of Drupal development is the filesystem layout. Where do we put a new module? In fact, you should never change anything in that directory.

    It is reserved for core Drupal modules only, and will be overwritten during upgrades. This is the location where all unmodified add-on modules ought to go, and tools like Drush a Drupal command line tool will download modules to this directory.

    In some sense, it is okay to put modules here. They will not be automatically overwritten during core upgrades. This has a few advantages. One is that standard add-on modules are stored elsewhere, and this separation makes it easier for us to find our own code without sorting through clutter. There are other benefits such as the loading order of module directories , but none will have a direct impact on us.

    This follows Drupal best practices, and also makes it easy to find our modules as opposed to all of the other add-on modules. The Drupal 7 Module Development book offers a project-based approach that walks readers through the most important, new, and changed concepts in-depth, allowing you to put these into practice.

    The authors of this edition of the book have much more than "merely" a deep understanding of Drupal 7's internals—in many cases, they literally wrote the very patches that put those internals into place.

    Larry Garfield is the chief architect behind Drupal 7's new object-oriented database abstraction layer, and Drupal core's database system maintainer. John Wilkins engineered much of the improvements to template files and theme system internals in Drupal 7, based largely on his cutting-edge work on the Zen theme. Ken Rickard spear-headed numerous improvements to Drupal 7's node access system after exploring its outer limits in his contributed Domain Access and Menu Access modules.

    Greg Dunlap's work with core API documentation has many times ferreted out particularly hard-to-find bugs. It's my sincere hope that this book finds many eager readers who are able to not only extend Drupal 7 to meet their specific needs, but also join our vibrant development community to contribute back what they learn and help make Drupal even better.

    Similar articles

    Copyright © 2019 podmimokongist.ml. All rights reserved.