Dries Buytaert: Major version upgrades in Drupal: tools and workflow
When a new major version of Drupal is released, custom code often requires updates to align with API changes, including the removal of deprecated APIs.
Because I keep forgetting certain aspects of this workflow, I decided to document it for future reference.
Tools overview
Tool Interface Functionality Target Audience Upgrade Status module UI in Drupal Identifies deprecated code, hosting environment compatibility, and more Site administrators and developers Drupal Check Command-line Identifies deprecated code Developers, especially during coding and continuous integration (CI)Upgrade Status module
The Upgrade Status module assesses a Drupal site's readiness for major version upgrades by checking for deprecated code and other compatibility issues.
Install the Upgrade Status module like you would install any other Drupal module:
[code bash]$ ddev composer require –dev drupal/upgrade_status[/code]Here,
ddev
is the tool I prefer for managing my local development environment.composer
is a dependency manager for PHP, commonly used to install Drupal modules. The–dev
option specifies that the module should be installed as a development requirement, meaning it is necessary for development environments but not installed on production environments.Enable the Upgrade Status module:
[code bash]$ ddev drush pm-enable upgrade_status[/code]drush
stands for "Drupal shell" and is a command-line utility for managing Drupal sites. The commandpm:enable
(wherepm
stands for "package manager") is used to enable a module in Drupal.- After enabling the module, you can access its features by navigating to the Admin > Reports > Upgrade status page at
/admin/reports/upgrade-status
.
Upgrading PHP and MySQL using DDEV
The Upgrade Status module might recommend updating PHP and MySQL, per Drupal's system requirements.
To update the PHP version of DDEV, use the following command:
[code bash]$ ddev config –-php-version 8.3[/code]To upgrade the MySQL version of DDEV and migrate your database content, use the following command:
[code bash]$ ddev debug migrate-database mariadb:10.11[/code]After updating these settings, I restart DDEV and run my PHPUnit tests. Although these tests are integrated into my CI/CD workflow, I also run them locally on my development machine using DDEV for immediate feedback.
Drupal Check
Drupal Check is a command-line tool that scans Drupal projects for deprecated code and compatibility issues.
Installation:
[code bash]$ ddev composer require –dev mglaman/drupal-check[/code]Run Drupal Check from the root of your Drupal installation:
[code bash]$ ./vendor/bin/drupal-check –memory-limit 500M docroot/modules/custom[/code]I usually have to increase the memory limit, hence the
--memory-limit 500M
.
Specbee: Why and How to migrate your DotNetNuke (DNN) site to Drupal 10
PreviousNext: Filtering and sorting search results by date range with OpenSearch
How to make use of OpenSearch (and Elasticsearch) built-in data-types specifically designed for filtering and sorting date ranges.
It's fairly common to have content with a date range. E.g., events or content that is only applicable for a given date.
Sorting and filtering results by date can be complicated, especially if you have to support features such as multiple date ranges and optional end dates.
But OpenSearch (and Elasticsearch) have data types specifically designed for this use case.
The key here is to index your data using a Range field type.
Let's consider an example we recently built for NSW.gov.au. The requirements for the field were as follows:
- Index a grant content-type
- The grant content-type has a date-range field
- The field has optional end dates via the Optional End Date module
- The field is multi value
- There is also a boolean 'Grant is ongoing' field that flags the grant as 'Evergreen'
The filtering requirements include a 'Status' field, which has options for:
- Open - the current date must fall inside one of the date-range values
- Closed - the current date is after date-range values
- Opening soon - the current date falls inside a future date range
Additionally, the search results should be sorted in the following order when no keywords exist:
- Open
- Opening soon
- Closed
Defining a date range field in Drupal/Search API
The first step is to inform Search API about the date-range data type. How you do this will depend on whether you're using Elasticsearch connector or Search API OpenSearch.
If you're using Search API OpenSearch, the good news is that it is already supported in the 2.x branch.
If you're using Elasticsearch connector, you should implement hook_elasticsearch_connector_supported_data_types_alter
and add date range as a data-type - something like this
/**
* Implements hook_elasticsearch_connector_supported_data_types_alter().
*/
function YOURMODULE_elasticsearch_connector_supported_data_types_alter(array &$data_types) {
if (!in_array('date_range', $data_types)) {
$data_types[] = 'date_range';
}
}
If you're using Elasticsearch connector, you also need a processor plugin to put the field values into the index. You can take inspiration from how Search API OpenSearch achieves this.
Indexing Drupal data
Once you have those pieces in place, you simply need to configure your date field to use the Date Range data type in the Search API index.
Constructing the queries
With the data in your index, the only thing left is to construct your queries to make use of the date range data-type.
In these examples, we'll assume your date-range field is called 'application_dates', that the field is multi-value and that the end date is optional.
We will use 1710201396000 as the current timestamp (in epoch microseconds).
Filtering to 'open'
This one is the simplest. You need a new term
query that uses the current date
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"application_dates": 1710201396000
}
}
]
}
}
}
For a date-range field, the use of a term query will match any document where the given value is between the start and end of the range.
Filtering to 'closed'
This one is a bit more involved. We need to combine some conditions
{
"from": 0,
"size": 10,
"query": {
"bool": {
"minimum_should_match": 1,
"should": {
"bool": {
"minimum_should_match": 1,
"must_not": [
{
"range": {
"application_dates": {
"gte": 1710201396000
}
}
},
{
"term": {
"grant_is_ongoing": true
}
}
],
"should": [
{
"range": {
"application_dates": {
"relation": "WITHIN",
"lte": 1710201396000
}
}
}
]
}
}
}
}
}
First, we have a should, which is an OR query in OpenSearch parlance. We're saying the grant must not have any future open dates (gte: 1710201396000) AND must not be flagged as ongoing. Then we're saying all of the application dates should be in the past (lte: 1710201396000).
Filtering to 'opening soon'
Here again, we need multiple conditions.
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": {
"range": {
"application_dates": {
"relation": "WITHIN",
"gte": 1710201396000
}
}
},
"must_not": [
{
"term": {
"application_dates": 1710201396000
}
},
{
"term": {
"grant_is_ongoing": true
}
}
]
}
}
}
First, we are saying there must be at least one date where the date range is in the future (gte: 1710201396000) and that the grant must not be ongoing OR have any date ranges that match the current date (term: 1710201396000) (i.e. are open).
Sorting
Sorting is a little more complex. We can make use of filters in our sort expressions.
To do this, we also need to index our date-range as an object so we can use nesting.
We duplicate the application_dates
field to an application_dates_sort
field and make this use the nested
data-type. The mapping will look like this
{
"application_dates_sort": {
"type": "nested",
"properties": {
"gte": {
"type": "long"
},
"lte": {
"type": "long"
}
}
}
}
Then, we can make use of this in our sort expressions. E.g. to have open items appear first, we can use
{
"from": 0,
"sort": [
{
"application_dates_sort.lte": {
"order": "asc",
"mode": "min",
"nested": {
"path": "application_dates_sort",
"filter": {
"bool": {
"must": [
{
"range": {
"application_dates_sort.lte": {
"gte": 1710201396000
}
}
},
{
"range": {
"application_dates_sort.gte": {
"lte": 1710201396000
}
}
}
]
}
}
},
"missing": "_last"
}
}
],
"size": 10
}
What we're doing here is sorting by the opening date, ascending, but using a filter to only match on records where the current date falls between the start/end date. We're telling OpenSearch to put any objects that don't match (missing
) at the end.
We can stack sort expressions like this — subsequent expressions will apply to those that were 'missing' from the first sort. Combining these lets us achieve the desired sort order of opening -> opening soon -> closed.
Wrapping up
OpenSearch is pretty powerful. But to make the most of its features, you need to ensure your data is mapped into the right data-type. Using date-range fields for storing date-ranges takes a little bit of extra planning, but it leads to much more efficient queries and a better experience for your users.
Tagged
OpenSearchTalking Drupal: Talking Drupal #454 - Drupal API Client
Today we are talking about Drupal’s API Client, What it does, and why you might need it with guest Brian Perry. We’ll also cover Iconify Icons as our module of the week.
For show notes visit: www.talkingDrupal.com/454
Topics- Brian what is new with you!
- Elevator pitch for Drupal API Client
- What was Pitchburg like
- Is this a normalizer for JSON API
- Why is this JS framework agnostic
- What is typescript and how does Drupal API Client use it
- Looking at the quick start guide the second step is to create an instance, where do you do that
- Who is this module for
- Will Drupal API Client be added to core
- What is on the roadmap
- How does this relate to Chapter Three and Next.js
- What is the spin up time
- How will Starshot impact this
- API Client
- API Client Quick Start
- NPM Packages
- Ideas Queue Issue - Promote API client packages to Drupal NPM namespace
- Drupal at your Fingertips
- Open collective
- JSON API Schema
Brian Perry - brianperry.dev brianperry
HostsNic Laflin - nLighteneddevelopment.com nicxvan John Picozzi - epam.com johnpicozzi Randy Fay - rfay
MOTW CorrespondentMartin Anderson-Clutz - mandclu.com mandclu
- Brief description:
- Have you ever wanted to empower your content creators to place icons from a massive, open source library into your Drupal site? There’s a module for that.
- Module name/project name:
- Brief history
- How old: created on May 22 of this year, so less than two weeks ago, by David Galeano (gxleano) of Factorial
- Versions available: 1.0.0 which supports Drupal 9.3 or newer, right up to Drupal 11
- Maintainership
- Actively maintained
- Security coverage
- Test coverage
- Documentation
- Number of open issues: 2 open issues, neither of which are bugs
- Usage stats:
- 1 site
- Module features and usage
- Out of the box the module provides both a CKEditor button for placing icons, and a new field type. It even provides a new form element that can be used in custom forms, a render element you can use to programmatically put an icon into something like a custom block, and a Twig extension that can be used to place icons in templates.
- According to the project page, the Iconify icon library includes more than 200,000 icons, though in my limited experimentation it seems like there are some duplicates between icon sets. Speaking of which, Iconify provides over 150 different icon sets, and in this module’s configuration you can specify which ones you want to be available on your site.
- Placing an icon is as simple as using an autocomplete to search the names of the icons available, and a preview is shown for each of the matches found.
- The field widget and the CKEditor button both give content creators options for what size and color to use for the icons. For myself I’d prefer to lock some of those options down (for example, make that part of the field’s display configuration instead), but I’m sure that could be added as part of a different widget.
- I can think of a few Drupal sites I’ve built where this would have been really handy, so I’m interested to play around with this module some more, and see how it evolves.
The Drop Times: Drupal's New Horizons: Innovations, Community, and the Starshot Initiative
Drupal's popularity is soaring because it's easy to use and flexible enough to fit any project. Businesses love it for its ability to grow with them, whether they're just starting out or already established. With each update, Drupal improves, offering more features and making it easier for everyone to build amazing websites.
One big thing to watch out for is the Starshot Initiative. It's all about making Drupal easier to use by adding some cool features from the start. Think of it as getting a new phone with all the apps you need installed. Starshot is like that for Drupal, making it simpler for everyone to get started and build something great.
The best part about Drupal is its community. People worldwide come together to share ideas, help each other, and improve Drupal. Whether you're a beginner or an expert, there's always something new to learn and someone to help you.
As Drupal grows, so does its potential. More and more businesses are choosing Drupal because it's reliable, adaptable, and just plain works. With initiatives like Starshot on the horizon, Drupal's future looks brighter.
With that said, let's now explore what updates and news we have covered last week:
In the interview with Alka Elizabeth, sub-editor at The Drop Times, Esmeralda Braad-Tijhoff, discusses her background, rise in the Drupal community, and ongoing efforts to promote inclusivity and collaboration within the tech industry. She shares insights into her roles with the Stichting Drupal Nederland and the Network of European Drupal Associations (NEDA), reflecting on her achievements and vision for the future of open-source solutions in public sector projects.
I had the opportunity to connect with some of the speakers of the upcoming DrupalJam to gain their insights on their sessions. Frederik Wouters sheds light on integrating RAG and OpenAI technologies within organizational infrastructures, emphasizing the significance of data quality and privacy considerations. Mikko Hämäläinen delves into the complexities of Digital Experience Platforms (DXP), elucidating their role in addressing customer expectations and internal silos in customer management. Finally, Mathias Bolt Lesniak advocates for the importance of open-source software in governmental policies, urging society to rediscover its benefits and advocate for its adoption.
Additionally, PHPCamp took place on 8th June 2024. I spoke with the organizers to provide insights into what attendees could expect. Amit Kumar Singh, a key organizer, shared his thoughts on why PHPCamp holds significance in the tech community.
Recently, Jay Callicott, an experienced Drupal Architect, introduced a new tool: DrupalX. DrupalX aims to simplify the process of building enterprise-level websites using Drupal. The Drop Times approached him for a comment, where he highlighted DrupalX's focus on improving the Drupal development experience, particularly for enterprise projects. Jay anticipates DrupalX will be beneficial in addressing common challenges developers face. Click here to read more about DrupalX.
The Drupal Starshot Initiative is picking up speed, and if you're interested in getting involved, now's the perfect time! The complete session calendar is now accessible, featuring a range of interactive Zoom calls. These sessions are tailored to offer updates and guidance on how you can contribute to this thrilling initiative.
After its unveiling at DrupalCon Portland 2024, the initial Drupal Starshot session, spearheaded by Dries Buytaert on May 31, 2024, attracted over 200 participants. The session discussed key topics such as community involvement, funding strategies, and governance plans. These discussions underscored the project's mission to streamline Drupal site construction through improved features and accessibility.
The Drupal Starshot project has introduced its new leadership team headed by Dries Buytaert. This team comprises key figures such as Technical Lead Tim Plunkett, User Experience Lead Cristina Chumillas, Product Owner Pamela Barone, and Contribution Coordinator Gábor Hojtsy. Together, they are committed to elevating the Drupal platform by prioritizing product vision, technical excellence, and user experience.
The Drupal Association has invited leaders of Local Associations from Asia to the inaugural Local Association Leaders meet-up on June 11, 2024. This initiative aims to strengthen the success of Drupal Local Associations by directly involving community leaders committed to advancing the Drupal project within their respective regions.
To celebrate Pride Month 2024, the Drupal Association is highlighting international LGBTQ+ organizations and donating proceeds from Pride-themed apparel sales. Community members can vote for the recipient organization, and they're encouraged to share their Pride stories for potential social media features.
The Drop Times has officially become a media partner for Drupaljam 2024, set to take place on June 12, 2024, at Fabrique Utrecht. We'll offer extensive coverage of all the latest updates throughout the event. But that's not all! The Drop Times has also been named the official Media Partner for DrupalCamp Spain 2024. This event is a cornerstone gathering for the Drupal community and is scheduled to be held from October 24 to 26 at the Hotel DeLoix Aqua Center. Stay tuned for comprehensive coverage of both Drupaljam 2024 and DrupalCamp Spain 2024!
Twin Cities Drupal Camp has opened the Call for Submissions for its upcoming event on September 12-13, 2024. With rolling session acceptance, early submissions have a higher chance of selection. The event will feature general sessions lasting 45 minutes, allowing for interactive audience Q&A sessions.
Registration for DrupalCamp Asheville 2024 is now open. The camp, which will take place from July 12 to 14, 2024, offers an exciting lineup of events. The camp includes three days of training, an unconference, various sessions, and community activities, all set against the scenic backdrop of Asheville.
In other news, MidCamp will return with new dates in 2025, from May 20 to 22, at the DePaul University Student Center in Chicago. This change aligns with an earlier DrupalCon, providing the community a great opportunity to gather in the spring. Key events leading up to MidCamp include opening the call for speakers in the fall of 2024, with final selections and the schedule announcement expected in late January or early February 2025.
It summarises the week's major updates, though we couldn't include every story in this selection. Until next week...
To get timely updates, follow us on LinkedIn, Twitter and Facebook. Also, join us on Drupal Slack at #thedroptimes.
Thank you,
Sincerely
Kazima Abbas
Sub-editor, The Drop Times
LN Webworks: Drupal Translation Module: How to Create Multilingual Drupal Websites
It typically occurs when you click on a website and become disinterested in utilizing it because there are no language preferences. In addition, you will be more interested in browsing the website if you can easily navigate its user interface and select your preferred language, regardless of where you live.
According to some reports: Multilingual websites can reach 75% more internet users and improve user experience, as 60% of global consumers prefer browsing in their native language. Businesses with such websites see a 70% average increase in conversion rates. That’s why it is preferred that you must create a multilingual website to help with website traffic and your business strategy.
How?
The Drop Times: DrupalCollab: Drupal Community in the Largest 500 Cities in the World
The Drop Times: On Using LinkedIn to Analyze the Size of the Drupal Community
joshics.in: Drupal 10: Not Just Another Upgrade, But a Revolution in Web Development
Ever had to scratch your head, ferreting out the secret weapon behind those mammoth success stories of the digital world? Well, ponder no more, you've just stumbled upon the world of Drupal 10!
As the latest prodigy of the Drupal family, Drupal 10 isn't just a facelift but a tool that champions uncharted territories. With an arsenal of new features, it's here to empower developers - both seasoned and novice ones.
Let's picture this through an everyday scenario. You're a site developer catering to a global audience. Earlier, you'd have to have multiple versions of the site to cater to various languages. Drupal 10 simplifies this with its built-in multilingual feature. You can now translate and localise your website without bothersome plugins.
Consider another common tussle developers face - keeping up with the digital world's insatiable appetite for interactive and responsive designs. With Drupal 10's layout builder, you can create and customize layouts per content type, per node, or even per user role.
Even SEO, the lifeline of online visibility, gets a boost with Drupal's 10 in-built meta tag and path auto modules. Now you can ensure your site stays in the limelight with less effort and more smart work.
Yet the standout trait of Drupal 10, one that deserves a tip of the hat, is the ease of upgrade. Remember the hair-pulling days of upgrading from Drupal 7 to 8? Those days are in the rear view mirror as Drupal 10 ensures a seamless upgrade, promising the preservation of custom themes and modules.
In conclusion, Drupal 10 is not just a new version, but a pivotal shift in web development that caters to today's fast-paced, ever-evolving digital landscape. It's about time we embrace it!
Drupal 10 Drupal Planet