Podcast Episode 3
New in Craft CMS 4.0
00:00 --:--
The episode cannot be loaded right now.
00:00 of --:--
Duration
11 min
Craft CMS 4.0 came out on Star Wars Day 2022, almost two and a half years after Brandon Kelly announced it at Dot All 2019 in Montreal. The pandemic was a big reason for the delay, and Craft 3.5, 3.6, and 3.7 had already brought massive changes in the meantime. Still, it's nice when the number before the dot changes, and Craft 4 is a great release.
What didn't make it into Craft 4.0
Some features announced at Dot All 2019 aren't part of 4.0. Of the new UI elements for field layouts, grid and horizontal rule already arrived with Craft 3.5 in 2020, but we're still waiting for fieldsets. Matrix in Matrix, which large parts of the community have wanted since 2014, was planned for Craft 4 and didn't make it either. The same goes for the additional element index views that were planned: table, tree, gallery, calendar, and board.
Author experience and user management
The biggest changes in Craft 4 are for content managers. Conditional fields let you show or hide fields and tabs in a field layout when a condition is met, for example a call-to-action button that only appears when another field is filled. WordPress developers know this from Advanced Custom Fields, and in Craft 4 it's part of the core. Element indexes get custom filters, so editors can show all entries by one author, all entries related to another section, or entries within a date range, and they can combine several filters for more detailed queries.
User management gets several smaller improvements. Users can now have addresses that plugins like Craft Commerce can access, the separate first and last name fields are replaced by a single full name field, and inactive users can represent a person or organization without login credentials. Users can also set their formatting locale to any language, not only the languages the control panel is translated into.
Assets, collections, and developer changes
In asset management, volumes no longer have types and are assigned to a filesystem instead. Image transforms can use their own filesystem, so originals can stay private while the transforms are public. Focal points can now be set in the asset preview, and there's finally a native alt text field. It isn't translatable yet, so multilingual sites should keep using a custom field for alt text.
Craft 4 brings Laravel collections to element queries. The new collect() method returns results as a collection instead of an array, for example {% set posts = craft.entries().section('blog').collect() %}, and eager-loaded elements are returned as collections as well. Other changes include drafts for categories, PHP 8 as the minimum requirement, a Money field type with a matching money Twig filter, environment variables that can override general config settings, database settings, and the site status, support for custom image transformers, {% cache %} tags that re-register external JavaScript and CSS files, and Symfony Mailer instead of Swift Mailer.
I see Craft 4 as a good update even without a big headline feature, with conditional fields coming closest. Editors benefit from accessibility improvements in the control panel, better performance for drafts and revisions, element index filters, and conditional fields. Developers get more flexible assets, better caching, more environment variables, and simpler Twig code with collections.
Mentioned in this episode
Thomas Sausen
Host