With the recent release of Drupal 10, the platform continues to gain momentum as new features and API improvements are already being prepared for the upcoming Drupal 10.1.x. In this blog post, we'll take a closer look at some of the enhancements that are expected to improve performance, reduce the hassle of writing new code, and support community initiatives for bug-fixing and addressing issues.
Drupal 10.0: Introducing Views Responsive Grid
If you haven't updated to Drupal 10 yet, you might be missing out on the responsive grid feature, which was not included in Drupal 9.5 due to Internet Explorer 11 support. Responsive grid allows developers and website owners to configure the maximum number of columns, the minimum grid cell width, and gutter spacing. This results in a more efficient grid configuration that no longer requires custom code or contributed modules.
Drupal 10.1: Enhancements in CSS and JavaScript Aggregation
While Drupal core has featured CSS and JavaScript aggregation for over a decade, the previous implementation faced several issues and needed an update. In Drupal 10.1, the aggregation generation logic has been completely rewritten, offering:
- Aggregates built by a dedicated route for improved cache performance and robustness against race conditions.
- Inclusion of JavaScript minification in the core, reducing the need for contributed modules and increasing efficiency.
Constructor Property Promotion for Smoother Code Writing
With Drupal 10's requirement of PHP 8.1, developers can now enjoy reduced boilerplate when defining a constructor, resulting in a more streamlined coding experience.
PHP 7:
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Creates ConfigManager objects.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
}
PHP 8:
/**
* Creates ConfigManager objects.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager,
) {}
PHP Attributes for Enhanced Metadata Management
PHP 8 introduces attributes, a native support for metadata management with less parsing overhead. Although Drupal 10 does not yet support attributes, the feature is expected to be included in Drupal 10.1 or later releases, allowing for a smooth transition away from annotations.
Here's an example of a block annotation (note the multiple levels of nesting, e.g., @Block -> @ContextDefinition -> @Translation
):
/**
* @Block(
* id = "test_context_aware",
* admin_label = @Translation("Test context-aware block"),
* context_definitions = {
* "user" = @ContextDefinition(
* "entity:user",
* required = FALSE,
* label = @Translation("User Context"),
* constraints = {
* "NotNull" = {}
* }
* ),
* }
* )
*/
With PHP 8.1, this can be changed to:
#[Block(
id: "test_context_aware",
admin_label: new TranslatableMarkup("Test context-aware block"),
context_definitions: [
'user' => new EntityContextDefinition(
data_type: 'entity:user',
label: new TranslatableMarkup("User Context"),
required: FALSE,
constraints: [
"NotNull" => [],
]
),
]
)]
Tidier Issue Queues and Community Initiatives
Drupal's bug smash and needs review queue initiatives have made significant progress in triaging and resolving the platform's backlog of issues. With ongoing efforts and community involvement, we can expect a more streamlined and efficient issue-resolution process.
What's Next for Drupal?
Exciting new features such as the Project Browser and Automatic Updates are on the horizon and may be added as experimental core modules in Drupal 10.2 or 10.3. Stay tuned for more updates and improvements!