Entity API Course Updated to Cover the Use of PHP Attributes

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.

We previously performed extensive updates that rewrote all our tutorials that made use of annotations for Drupal plugins. See Keeping up with Drupal’s Evolving Plugin API: Updating Tutorials for PHP Attributes for more about those changes. But at that time, core did not yet support the use of PHP attributes for content or configuration entity type definitions. It does now, though!

What changed

At a high level, the metadata for custom content and configuration types is declared using PHP attributes instead of annotations. In your code, you’ll now author a #[ContentEntityType] or a #[ConfigEntityType] attribute, instead of a @ContentEntityType or @ConfigEntityType annotation, to provide details like the entity type’s id and label, and to configure handlers[], access control, and routing.

Seven tutorials in our Entity API course were rewritten and polished, and there’s a brand-new properties reference that dives deep into all the available #[ContentEntityType] attributes’ properties, what they do, and when to use them. In our research, we found that figuring this out still required quite a bit of code spelunking, so we wanted to surface as much of the information we found as we can. This new tutorial includes usage snippets that you can copy/paste, walking you through default values, types, and common pitfalls for identification keys, handlers, routing metadata, forms, Views integration, cache contexts, and nested arrays, such as links[] and handlers[].

We also took this opportunity to refresh the Entity API Implementation Basics tutorial based on feedback from members that said it was missing some critical information and was confusing. It now explains why you’d created a custom entity type in the first place, the differences between configuration and content entities, and the previous base-field code sample has been trimmed to its essentials to keep the focus on concepts. We also introduced bundle classes (and have another tutorial about these in the works), and updated the prerequisite of PHP attributes so the terminology stays consistent.

Should I use PHP attributes or annotations?

While annotations are still supported via a backwards compatibility layer, if you’re starting a new project, you should now use PHP attributes. We expect support for annotations will be dropped sometime in the future. Though not until Drupal 12, if not later.

The caveat to this is if you need your module to be compatible with versions of Drupal core before 11.1.0. In which case, you’ll still need to use annotations to define your custom entity types. Luckily, all the key/value pairs are still the same; it’s really just the syntax that’s different. So things like the new ContentEntityType Attribute: Properties Reference will still be useful.

Enjoy the updates, and please let us know if you have any questions about the move from annotations to PHP attributes.

Similar Posts

  • Tips for Streamlining Your Web Development Workflow

    Web development is an ever-evolving industry. That means we’re constantly adapting to what’s new, all while maintaining quality and efficiency. No sooner are we comfortable with something than it changes on us. This applies to our workflow just as much as it does to other parts of our business. The way we build websites must…

  • 10+ Best Free Personal Portfolio WordPress Themes in 2026

    Portfolio websites are a key part of any creative professional’s branding. They’re a place to showcase your work and share your expertise with prospective clients. On a personal level, they’re also a nice way to look back on your past achievements. WordPress is the perfect tool for creating an online portfolio. The content management system…

  • Vibe Coding for Marketers: A Beginner’s Guide

    You’ve heard “learn to build”, “ship your own tools”, “automate your busywork”, but nobody explains where to start. Canva made this painfully clear: they gave 5,000 employees a full week to explore AI, and most couldn’t figure out how to start. No surprise there, most vibe-coding tools expect you to manage files, wrangle a terminal, and…

  • Thousands of Public Google Cloud API Keys Exposed with Gemini Access After API Enablement

    New research has found that Google Cloud API keys, typically designated as project identifiers for billing purposes, could be abused to authenticate to sensitive Gemini endpoints and access private data. The findings come from Truffle Security, which discovered nearly 3,000 Google API keys (identified by the prefix “AIza”) embedded in client-side code to provide Google-related…

  • 7 Best VPS Hosting in Russia 2025,May🇷🇺[Reviewed]

    Do you want to attract Russian visitors to your blogging/business website? Even more, do you require Separate Dedicated Resources such as CPU/RAM/Storage for your upscaling websites that too at a fair price? Do you have an e-commerce website and wish to expand into the Russian economy?  Try Using the Best VPS Hosting Services from Russia,…