New EntityReference filter for Drupal Views

Drupal 11.1 was released yesterday, and one of the most important things in this release is the addition of a new EntityReference filter for Views.

Before this version, if you wanted to add an exposed filter to an entity reference field — in my case, as shown in the image below, it's the field_related_articles field — the filter would be a simple text input field.

Image

Now, it can be a select box or an autocomplete field, as shown in the second image.

Image

What I don't like is that this filter isn't used by default; instead, you need to write a hook_views_data_alter() for that. In my example, it would look like this:

/**
* Implements hook_views_data_alter().
*/
function MY_MODULE_views_data_alter(array &$data): void {
$field_name = 'field_related_articles';
$data['node__' . $field_name][$field_name . '_target_id']['filter']['id'] = 'entity_reference';
}

Read more in the change record.

UI for viewing, reverting and deleting taxonomy term revisions in Drupal 10.3

Taxonomy terms have been revisionable for quite some time now. If you take a look at the change records, you'll see that several years have passed since terms began supporting revisions.

The only issue was that Drupal core did not provide a User Interface (UI) for managing these revisions. However, this changes with the release of Drupal version 10.3, where a user interface for revision management has finally been introduced.

Change record: https://www.drupal.org/node/3396786

Drupal 10.3.0 is scheduled for release in the week of June 17, 2024.

File name sanitization in Drupal 10.2

It's not exactly a feature peak, but it is a new feature in Drupal that is still relatively unknown, so I'm writing about it.

Every time I created a social share image for my blog post in Canva, I had to change the file name after downloading to replace spaces with a middle dash, and convert uppercase letters to lowercase. However, starting with Drupal 10.2, this is no longer necessary. From this version onwards, there is an option for file name sanitization.

You can find this option on the following page: /admin/config/media/file-system.

Image

The file name is changed during the file upload, either through the UI or via REST. For more information, please refer to the change record.

Using PHP attributes for Drupal plugins

Starting with Drupal version 10.2, it will be possible to use PHP attributes instead of annotations for some plugins. Currently, this applies to Action and Block plugins. For more information, please see the following change record:

https://www.drupal.org/node/3395575

Let's take one of my modules, Facets Block, as an example. Here's how the block plugin would look with annotations and with attributes.

Before:

/**
 * Provides a 'Facets Block' block.
 *
 * @Block(
 *  id = "facets_block",
 *  admin_label = @Translation("Facets Block"),
 * )
 */
class FacetsBlock extends BlockBase implements ContainerFactoryPluginInterface {
  ...
  ...
}

After (Drupal 10.2+):

use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides a 'Facets Block' block.
 */
#[Block(
  id: 'facets_block',
  admin_label: new TranslatableMarkup('Facets Block')
)]
class FacetsBlock extends BlockBase implements ContainerFactoryPluginInterface {
  ...
  ...
}

To make this work, don't forget to add the appropriate classes (Block and TranslatableMarkup) in the use section and to clear the cache.

Using PHP attributes, rather than annotations that are essentially PHP comments, for adding structured metadata to classes is more appealing to me. So, I definitely plan to use this in the future.

Project Browser

The Project Browser aims to simplify the process of finding and installing modules for both site builders and developers. You've got two options: First, you can use the browser to search for modules and see the necessary Composer and Drush commands for installation. Second, you can actually install modules directly using the UI.

Right now, the module is in beta, and the feature for installing via the UI is still experimental. I gave it a try and encountered some errors, so it seems we'll need to wait a bit longer for it to be fully reliable. That said, the Project Browser is already a handy tool for browsing modules. It's more user-friendly than drupal.org, thanks to improved search and filtering options.

This Project Browser is part of a larger effort to make Drupal more accessible, especially for those who are new to the platform.

Improved field creation in Drupal 10.2

In Drupal, adding fields via the UI can challenge both beginners and seasoned users. Thankfully, Drupal 10.2 is set to offer a more intuitive process with detailed explanations for each field type.

Drupal 9 vs Drupal 10.2 field creation:

This is part of a broader initiative to enhance the field creation experience. For more details, check out the following issue on Drupal: https://www.drupal.org/project/drupal/issues/3346539

Reuse of existing fields in Drupal 10.1

I'm really impressed with the UX enhancements in the recent Drupal 10.1 release, particularly regarding the reuse of existing fields.

On the left is the previous functionality, while on the right you can see the improvements in the latest Drupal 10.1 version.

This is part of a broader initiative to enhance the field creation experience. For more details, check out the following issue on Drupal: https://www.drupal.org/project/drupal/issues/3346539