Being able to execute, and step debug, Drupal's test using the PhpStorm UI makes it easier and more efficient to write tests for your projects. Learn how to configure PhpStorm to run Drupal's PHPUnit tests inside of a DDEV environment using docker-compose and a remote PHP CLI Interpreter. This setup will work for both Drupal core and your custom code.
Twig is a template engine for PHP, which is the language used in Drupal. Twig can be used to design templates in generic PHP applications as well as Drupal themes.
We've got a lovely mix of announcements for you today: Drupal's latest minor release, 10.2.x is now available; a new major release schedule for Drupal was recently announced; ICYMI: videos added to 4 tutorials in our new Routes and Controllers in Drupal course; and our office is officially closed the week of December 25 through January 1.
Free Coaching for the Drupal Community
Blog postIn 2024 I became a certified coach to round out the informal coaching that I’ve been providing for many years.
Object-Oriented PHP
TopicObject-oriented PHP utilizes classes and objects to organize code into reusable chunks. This approach helps us organize complex applications, such as Drupal, into modular code called classes that can be reused across the entire system.
Meet the New Drupalize.Me AI Assistant
Blog postWe’ve been experimenting with different ways to use AI to make Drupalize.Me even more helpful for our members and we’re excited about this first update: a new AI-powered chatbot that can search and summarize tutorials from our library.
As of Drupal 11.1.0, core has support for defining custom entity types (both content and configuration) using PHP attributes instead of annotations. And now, all our Entity API tutorials have been updated to reflect this change.
At Drupalize.Me, one of our goals is to provide learners with up-to-date resources that align with the latest best practices. To that end, I recently worked to update our tutorials to reflect the transition from PHP annotations to PHP attributes for plugin discovery. I blogged previously about why this transition is happening.
As Drupalize.Me’s tutorial library continues to grow, these kinds of changes touch ever larger numbers of existing tutorials. Plugins is an interesting one because we have tutorials that teach the inner workings of the Plugin API. And, we have tutorials about things like blocks, field types, and views plugins, that while not specifically about the Plugin API, make use of it. This ended up being one the most significant updates we’ve made since the release of Drupal 8.
In short, the updates are necessary because Drupal is transitioning from annotations to native PHP attributes. And while annotations will continue to work for the foreseeable future, we wanted to make sure that the code examples, and recommendations, you find on our site are aligned with that code you’ll see in the latest versions of Drupal core.
Configuration API in Drupal
CourseWhile working on a Drupal core bug in the Navigation module’s toolbar, Mike Herchel discovered the issue was related to the usage of Drupal.displace(), which is included in Core’s JavaScript and CSS APIs. He breaks down what Drupal.displace() is and how to use it.
Entity API in Drupal
CourseOn occasion, you may need to modify the behavior of entity types defined by another module. Thankfully, Drupal includes several alter hooks that can be used to override the behavior of another entity.
In this tutorial, we will:
- Walk through the common Entity API hooks
- Look at example implementations of each
- And discuss the use cases for each
By the end of this tutorial, you will have a better understanding of how to override the default behavior of an entity type provided by Drupal core (or another contributed module) within your custom code.
The Typed Data API in Drupal helps add additional functionality to PHP's built-in data types, making working with data in Drupal much more predictable. It allows code to make intelligent guesses about the type of data that a field on an entity contains. For example, differentiating between a string of text and a string of text that represents a URL.
In this tutorial, we'll:
- Look at the 3 main types of typed data in Drupal: primitives, complex data, and lists.
- See how different data types and definitions are defined, and show how to define your own data type.
- Look at the interfaces provided by each data type to see some of the benefits of adding this abstraction layer.
By the end of this tutorial, you should have a better understanding of what the Typed Data API is, where you'll most likely encounter it, and how to use it in your code.
Entity CRUD (Create, Read, Update, and Delete) operations are handled via the EntityTypeManager service.
In this tutorial we'll:
- Learn how to use the
EntityTypeManagerservice to perform basic CRUD operations with examples you can copy/paste - Access both property and field values of an entity
- Update entities by setting new field values and then saving the object
By the end of this tutorial, you'll be able to understand Entity CRUD operations and be well on your way to becoming comfortable with accessing and manipulating entity values in code.
Field formatters are responsible for taking the data stored by a field and transforming it into what a visitor sees. We can define new field formatters to output data for new field types or to provide alternative formatting options for existing field types. Creating a field formatter plugin is a common task for Drupal developers.
In this tutorial we'll:
- Define a new background color field formatter that uses the string stored by our field_example_rgb field type as the background color of the output.
- Make it possible for site builders to toggle on or off a feature that automatically adjusts the foreground text color of the output.
By the end of this tutorial you should be able to define a new custom field formatter plugin with settings that a site administrator can configure.
Field API Overview
FreeIf you've ever created or edited a piece of content on a Drupal site you have already interacted with the Field API. The Field module (along with its user interface counterpart) is responsible for providing the forms and data components used to build up the content model that make up a Drupal site. Understanding how Drupal fields work and how they're constructed via the Field API is an important part of understanding how Drupal works.
In this tutorial, we're going to look at the main components that make up the Field API at a high level. We'll see how the Field UI module exposes the field types included in core. We'll also look at the three main pieces that compose fields: types, widgets and formatters.
Drupal's Field API specifies the implementation details for field types, widgets and formatters. It also provides several hooks that allow custom code to alter these implementation details. In this tutorial we'll take a look at these Field API hooks and see how they can be used to change field types, widgets and formatters.
By the end of this lesson, you should be able to:
- Identify existing Field API hooks for manipulating field behavior
- Understand the proper method for changing the behavior of a field type, widget or formatter
- Know where to find the documentation for these API functions, and how to find their implementations