New in Craft CMS 4.0
Since Craft's unveiling nine years ago, the creators behind the CMS have focused on a good user experience for content managers. Content teams should easily manage multi-layered content models daily without increasing training.
Content in Craft sometimes has complex relationships, multiple categories, matrix fields, and files. Having all of this maintainable in a user-friendly way in the control panel, without performance issues, is a challenge. Fortunately, Craft 4 features the most significant innovations in precisely these areas:
Conditional Fields
Field layouts and tabs within the control panel can now be shown and hidden if a specific condition is met. For example, you could show a CTA only if another field is filled. Anyone using WordPress with Advanced Custom Fields will already be familiar with this feature, and with Craft version 4.0, it is part of the core.
User Management
Regarding user management, there are several minor optimizations, but all of them are extremely helpful. Users can now manage addresses that can be accessed by plugins like Craft Commerce. Also, users no longer have a single field each for "First Name" and "Last Name", but simply the "Full Name" field, from which first and last name can then be extracted for sorting purposes.
Inactive users can be used to manage users who represent a person or entity but do not require credentials.
Users can now set their formatting language to any known language, not just the one for which the control panel has been translated.
Assets
Craft CMS 4 also improves file management. For example, volumes no longer have associated types and are instead assigned directly to a "file system".
Image transformations can now be assigned to a separate file system. For example, the original images could use a non-public file system, while the transforms use a public file system.
Setting a focus point no longer works exclusively in the image editor but is already in the preview window. Also, there is finally a native alt text field for images. Not the biggest change, but at least one less field to create once working with images in the CMS.
A native field for alt-text
Otherwise, there is finally a native alt text field for images. It is not the most significant change, but at least one less field to create once working with images in the CMS. Unfortunately, the native alt text field is not translatable to multiple languages. This feature is only planned for Craft 5, and thus multilingual websites should continue to use a separate field for the alt text of images.
Element index filtering
The new filtering of entry elements in the control panel is helpful, especially for projects with many entries. Thanks to the user-defined filtering of element indexes, all entries of an author can thus be displayed dynamically. Multiple filters can also be linked together to allow extensive queries.
Collections
Craft 4 brings Laravel Collections for data arrays to the CMS. Element queries now include a collect() method that returns query results as one of these collections instead of an array:
{# Collection #}
{% set posts = craft.entries()
.section('blog')
.collect() %}
Collections also support eager loading and are therefore suitable for files. While in Craft 3, the image URL was retrieved within an array, this is now done via a collection, for example, if only the first image is to be displayed:
{{ entry.image.collect().first().url() }}
Others
- It is possible with Craft 4 to save the categories as drafts. Therefore categories are now closer to entries in terms of functionality and flexibility.
- Craft now requires PHP 8, allowing developers to take advantage of several new language features.
- Craft now includes a built-in "money" field type and a new Twig filter 'money'. Useful, for example, in e-commerce environments where a currency-dependent display of money amounts is required.
- Environment variables can override most general configuration settings and database connection settings. Also, the site status can be set with environment variables.
- It is now possible to register custom image transformers that no longer use the built-in GD/ImageMagick-based transformer.
- The {% cache %} tags now keep track of all external JavaScript and CSS resources that have been cached and register them again the next time the page is loaded.
- Craft CMS now sends emails using Symfony Mailer instead of Swift Mailer.
Conclusion
Craft CMS 4 is a good update, even if the prominent new features were missing. The conditional fields are the closest to fall into this category. However, the community is waiting for Matrix in Matrix, initially planned for Craft 4.0. Nevertheless, all the improvements to the CMS ensure that it will be even more polished.
Optimized accessibility in the Control Panel meets better performance when creating drafts and revisions. By filtering entry items, editors can find specific entries that match the selected criteria more quickly. The integration of conditional fields also dramatically improves the Author's experience.
Developers will be pleased with the new flexible file management, better caching, the ability to set more environment variables, or simplify Twig code with Collections.
The whole is greater than the sum of its parts, and Craft now provides an excellent workflow for editors and developers.