Drupal Development
Refactoring Drupal batch API callbacks to increase testability
Drupal's Batch API is great, it allows you to easily perform long running processes with feedback to the user.
But during Drupal 8's development processes it was one of the remaining systems that didn't get the full object oriented, service-based architecture.
Much of the batch API is largely unchanged from Drupal 7.
But that doesn't mean you can't write unit-testable callbacks.
Let's get started.
A quick gotcha with Drupal 8's libraries.info.yml and aggregated JavaScript
This one tripped me up on a recent Drupal 8 project.
Easy to miss when you're working in a development oriented environment with things like JavaScript preprocessing turned off.
A JavaScript file was being added just fine with aggregation turned off, but not getting added with it turned on.
Making Drupal 8's menu active trail consider query arguments
On a recent Drupal 8 client project our client was building listing pages using views exposed filters and adding these to the menu.
This resulted in several menu URLs pointing to the same base path, but with the query arguments determining the difference.
However Drupal 8's default menu-trail calculation was resulting in the menu highlighting all instances when one of them was viewed.
Luckily the active trail calculation is done in a service and it was simple to modify the default behaviour.
Read on to see how we did it.
Native PHPStorm Drupal Test Runner
PHPStorm has a lot of built in test runners, but it doesn't support Drupal's Simpletest test runner. In this blog post we'll see how we can execute Drupal tests inside PHPStorm using Drupal test runner.
Ensuring Drupal 8 Block Cache Tags bubble up to the Page
Whilst working on a Drupal 8 project, we found that cache tags for a Block Content entity embedded in the footer weren't bubbling up to the page cache.
Read on to find out how we debugged this and how you can ensure this doesn't happen to you too.
Handling Errors in Complex Drupal Form Validation
Recently, I have been working on a site with a big multi-step form that is using a lot of custom form elements, custom auto-completes, custom form api states and ajax based sub-forms. It is all built using Drupal form api. The best thing about this form is that all the fields and sub-forms map to a data model.
Skinning HTML emails with Drupal using an existing front-end
A requirement that comes up from time to time is being able to use content stored in Drupal and produce rich HTML emails. In a lot of cases the design of these emails matches the design of the existing, already implemented front-end website.
In a recent project, we explored ways of creating HTML email’s which wouldn’t require us to start from scratch and would also evolve as the website’s look and feel did. Our design goals were thus:
- Use the existing website’s CSS to skin the emails.
- Use existing Drupal site-building tools to construct the markup for these emails.
- Allow admins to easily create and preview HTML emails.
Decorated services in Drupal 8
One of the aspects of the new object oriented architecture in Drupal 8 is the introduction of services. Services can be provided by any module and provide a mechanism for exposing reusable functionality by way of interfaces and classes. All services are instantiated via the container which is responsible for injecting a service’s dependencies.
Since services implement interfaces and are always instantiated via the container, we have the opportunity to alter what the container returns, ultimately allowing us to swap any existing service with a new one.
Agile Drupal development's role in the Service NSW portal
As part of our sponsorship of the GovInnovate conference, CeBIT conducted an interview with Owen Lansbury about Drupal's role on the Service NSW platform, including how the use of Agile development enabled it to go live in record time and be iteratively improved since launch.
aGov for Drupal 8: First Alpha Release
Since 2012, PreviousNext has been developing and maintaining the aGov distribution for Drupal 7. aGov provides a means for Australian Government organisations to meet their accessibility and security obligations with free and open-source software hosted on the platform of their choice.
In the last few weeks we have been working on the Drupal 8 version, and are happy to announce today the first Alpha release!
In this post we share some of our experiences developing a Drupal 8 distribution.