This tutorial covers writing a custom process plugin that you can use to manipulate the value of any field during the process (or transform) phase of a migration. Process plugins take an individual field value provided by a source plugin, and perform transformations on that data before passing it along to the load phase.
In this tutorial we'll write a process plugin that can either uppercase an entire string or the first letter of each word in the string depending on configuration.
By the end of this tutorial you should know how to start writing your own process plugins.
This tutorial covers writing a custom source plugin that imports data from a MySQL database into Drupal nodes. After completing this tutorial you should understand how to write your own custom source plugin that can:
- Extract data from an SQL source
- Describe the various fields in the source data to the Migrate API for mapping
- Provide unique IDs for each row of imported data
By the end of this tutorial you should be able write a custom source plugin that uses an SQL data store as well as have a foundation for writing source plugins that extract data from any source that PHP can read.
Why Is Learning Drupal Hard?
Blog postWhen it comes to learning Drupal I have a theory that there's an inverse relationship between the scope of knowledge that you need to understand during each phase of the learning process, and the density of available resources that can teach it to you. Accepting this, and understanding how to get through the dip, is an important part of learning Drupal.
When Drupal 8.1.0 was released it included some additions that broke our Get a Service from the Container tutorial in the Drupal 8 Module Development Essentials series. But don't worry, it's fixed now.
Free Hands-On Drupal 8 Lessons
Blog postThere is a lot of new ground to cover in Drupal 8, especially for developers. For those of you who are already familiar with developing in Drupal 7, these free Drupal 8 Activity Cards will help you with the leap. The cards were created by Tanay Sai and his study group while they bootstrapped themselves on the new code. They’ve done an awesome job covering the main topics you’ll need to know for the switch from Drupal 7 to 8. Each card is a lesson on a new development topic and altogether they cover 21 days of lessons.
Drupal 7 Critical Security Update Today
Blog postOn Tuesday, July 12th, the Drupal security team issued a Public Service Announcement (PSA) about
a *highly* critical security release that happened today, Wednesday, July 13th at 4pm UTC. This security release gets the extra push of *highly* and a PSA because this very dangerous vulnerability will allow an attacker to execute their own PHP code on your site. Here are a few important things to know.
Anyone writing JavaScript for Drupal should use the Drupal.behaviors
API when writing their custom JavaScript functionality. Doing so ensures that your JavaScript is executed at the appropriate times during the life cycle of a page, such as when the page loads, or after new DOM elements have been added via an AJAX request.
In this tutorial we'll look at:
- The problem that
Drupal.behaviors
solves - How to use
Drupal.behaviors
when writing your JavaScript code
By the end of this tutorial you should be able to explain what the Drupal.behaviors
API is, and be able to use it in your own JavaScript.
Release Day: JavaScript in Drupal 8
Blog postWe're happy to announce the addition of several JavaScript-related tutorials to our Drupal 8 Theming guide. These tutorials, along with our other tutorials on defining defining and attaching asset libraries will help you understand Drupal's JavaScript API and help you make sure your custom code follows the established best practices.
In Drupal, whenever we output markup it's best practice to use a Twig template or a theme function. But whenever you need to output DOM elements within JavaScript the best practice is to use the Drupal.theme
function. This function ensures that the output can be overridden just like the HTML output by Twig. This tutorial covers how to use the Drupal.theme
function in your JavaScript when inserting DOM elements, as well as how to replace the markup output by other JavaScript code that is using the Drupal.theme
function.
ESLint is the linting tool of choice for JavaScript in Drupal. In this tutorial we’ll show how to install the ESLint application and then use it to verify that your JavaScript files are meeting the Drupal coding standards.
Drupal (as of version 8.4) has adopted the Airbnb JavaScript coding standards. In this tutorial, we'll walk through how to install the necessary package dependencies to run eslint on JavaScript files within your Drupal site.
It's often useful to pass dynamically calculated values from the server to the client in order to make them available to your front-end JavaScript. Your JavaScript might need to know something particular about the user currently visiting the site or the value of a particular configuration variable. In this tutorial, we'll look at how Drupal can pass these values from the PHP code that executes during a page load to the front-end JavaScript in your theme.
In order to do this, we'll need to:
- Explain how drupalSettings bridges the gap between PHP and JavaScript
- Generate values for settings in PHP and make them available to JavaScript
- Make use of PHP generated settings within your JavaScript code
Sometimes your JavaScript needs to insert new strings into the user interface. In order to ensure that those user-facing strings can be translated into other languages, just like the rest of Drupal's user interface, you should make sure and use the Drupal.t
function anytime you output a string of text.
You may know that Drupal provides utility PHP functions for manipulating and sanitizing strings. Drupal also provides JavaScript functions for the same purpose. The two most useful are Drupal.checkPlain
and Drupal.formatPlural
. Drupal.checkPlain
lets you ensure a string is safe for output into the DOM; it is useful when working with user-provided input. Drupal.formatPlural
ensures that a string containing a count of items is pluralized correctly. This tutorial will show you where you can find documentation for and example use-cases of both.
Maybe you've heard of anonymous closures but you're not quite sure how they apply in Drupal, or why using them is considered a best-practice. Anonymous closures allow you to avoid accidentally clashing with anything in the global scope, as well as to alias the jQuery object to the more commonly used $
. This is necessary because Drupal runs jQuery in no-conflict mode. This tutorial will look at the syntax used for placing your custom JavaScript code inside an anonymous closure, and why it's a good idea to do so.
In this tutorial we'll:
- Explain what a closure is (briefly), and what immediately invoked function expressions are
- Show how typically Drupal JavaScript gets wrapped in a closure
- Provide a copy/paste example you can use in your own code
By the end of this tutorial you should be able to explain what an anonymous closure is, and how to use one in your custom JavaScript for Drupal.
More often than not, templates in a theme share common elements: the header, footer, sidebar, or more. In Drupal, themes created with a Twig template can be decorated by another one. This template inheritance allows you to build a base "layout" template that contains all the common elements of your layout defined as blocks. A child template can extend the base layout and override any of its defined blocks. This helps prevent code duplication, and keeps your theme more organized.
This tutorial is for theme developers who want to reduce code duplication in their themes, or anyone seeking to better understand how Twig template inheritance works. We'll cover:
- What the Twig
block
andextends
tags do - An example use-case for template inheritance
- How to extend a Twig template from another theme or module
- How to include other Twig templates
Info files, aka THEMENAME.info.yml files, provide Drupal with metadata about your theme, the features it supports, and the regions that it defines. All themes are required to have a THEMENAME.info.yml file, and creating one is generally the first step you'll take when creating a new theme.
In this tutorial we'll:
- Create a new .info.yml file and define a new theme
- Review the required key/value pairs of an .info.yml file
- Enable our new theme in the Drupal UI
By the end of this tutorial you'll be able start a new theme by creating the required *.info.yml file and better understand its contents.
Learn Views in Drupal 8
Blog postOne of the big changes in Drupal 8 is that Views, the most popular contributed module in Drupal 7, is now included as part of core. Learning Views is a key component of learning to build Drupal sites. Aside from having this tool built in core now, the beauty of this new feature is that it is almost identical to Views in Drupal 7. You can get started site-building with Views in Drupal 8 without waiting for any fancy version-specific instructions.
Google Summer of Code 2016 is on!
Blog postSummertime in the northern hemisphere means it’s time for Google’s Summer of Code (GSoC). In this great program, Google pays students to work on various open source projects for 10 weeks. Drupal was once again selected to mentor students. Our 11 students are working on some pretty cool projects with 26 community mentors.
What's New in Drupal 8.1.0
Blog postDrupal 8.1.0 was released on April 20th. There are a few things that are exciting about this release; in particular the 2 new experimental modules BigPipe and Drupal Migrate UI.
This week we're starting a whole new guide covering Drupal 8 migrations. We'll look at what migrations are, how they work, planning for a migration, the contributed module ecosystem, and performing a Drupal-to-Drupal migration.