Matt Glaman: Are you ready for Drupal 11 in 2024?

Drupal 11? Yes! Drupal 11 is going to release on August 2024 or December 2024. That's only a year and a half away when writing this blog post. So, when should we start preparing modules and sites for Drupal 11? Now! Preparing for the next major version of Drupal should not be a mad dash but a consistent process.

I'll be presenting at MidCamp tomorrow about lessons learned from this past Drupal 10 readiness effort. While strenuous, the Drupal 10 readiness work for contributed modules went well. It definitely went faster than Drupal 9. And that is because we have better tooling and processes. Those tools and processes need more refinement as we prepare for Drupal 11.

LN Webworks: Unlock the Power of Drupal 9 for Your Multilingual Website

The internet has dissolved the borders separating different countries to a great extent. Today, we can connect with someone miles apart within a fraction of a second, all thanks to internet technology. The internet, powered by incredible technologies such as Drupal 9 and multilingual websites, has broken down borders and connected people from all corners of the globe.



It depends on us whether we opt for internet calling, emailing, or chatting, but one thing is certain we are just a click away from those we aspire to connect with. Such incredible advancements have not only empowered human relationships, but have also opened monumental opportunities for businesses. If you have an inner hunger to establish your brand globally, nothing can confine you today. All you require to do is build a multilingual website and you are ready to reach a global target audience effortlessly.

Jacob Rockowitz: Frequently Asked Questions (FAQ) about the Schema.org Blueprints module for Drupal

In a recent blog post, I asked, "Is there no future for the Schema.org Blueprints module?" I wrote the blog post to determine what is next for the Schema.org Blueprints module. The overall feedback was positive, with very constructive criticism and advice. Reading the replies on Twitter, the comments on my blog, the pings in Drupal Slack, and tickets in the module's issue queue, I realized that people are interested in the Schema.org Blueprints module's overall goal, which is to build standardized and reusable content models in Drupal. Most of the questions and feedback I received were around clarifying the Schema.org Blueprints module's use case, getting started, and the project's roadmap.

Within the feedback, people raised many questions about the Scheme.org Blueprints module. I collected their questions and created a reasonably large FAQ page.

The first question I am answering is, "What problem is the Schema.org Blueprints module trying to solve?"

The FAQ page further defines the goals, use case, process, and best practices for the Schema.org Blueprints modules. I am still perfecting my elevator pitch for why someone should take a Schema.org-first approach and use this module. Once I can entice someone to try the module, the next step is to be helping them install,...Read More

Specbee: Understanding Update and Post Update Hooks for Successful Site Updates

Understanding Update and Post Update Hooks for Successful Site Updates Ankitha Shetty 25 Apr, 2023 Subscribe to our Newsletter Now Subscribe Leave this field blank

During core updates or module updates, it is crucial to ensure the stability and integrity of your Drupal website. Luckily, the Update API module and Update/Post Update Hooks are here to help.

The Update API module provides the hooks that are necessary for updating code and modules on your Drupal site. These hooks are nothing but Update and Post-Update Hooks which allow developers to customize updates according to their needs.

In this article, we’ll discuss the Update API, what are update and post-update hooks and when and how they should be used. By understanding both types of hooks, you can successfully update your Drupal site with minimal effort. Let’s get started!

Image removed.

The Update API

While working on an existing site, when you update code in a module, you may need to update stored data so that the stored data is compatible with the new code. You might have noticed errors like ‘The website encountered an unexpected error’ flash in front of you. Scary right!? I know! This is where Drupal’s Update API comes to our rescue.

If the update is between two minor versions of your module within the same major version of Drupal core, you can use the Update API to update the data. Update API allows you to provide code that performs an update to stored data whenever your module makes a change to its data model. The data model change refers to any change that makes the stored data on an existing site incompatible with that site's updated codebase. These Data model changes involve:

Updating the Configuration Schema

  • Adding/removing/renaming a configuration key.
  • Changing the data type of the configuration key.
  • Changing the expected default value of a configuration key, etc.

Updating the Database Schema

  • Adding/changing/removing a database table or field.
  • Moving the stored data to a different field or table.
  • Changing the format of stored data, etc.

Updating the Entities & Fields

  • Adding a new base field to an existing entity type.
  • Updating a field from an obsolete type to a new type, etc.

Updating the Data

  • Manipulate the stored data on an existing site.

Working with Update hooks

Hook hook_update_N() is used to introduce an update between minor versions of a module. These hooks are placed within your module in the *.install file.

The hook_update_N() is written in the form of (module name)_update_(number). Here N comprises of:

  • 1 or 2 digits refer to the  Drupal core compatibility (Drupal 8, 9, 10, etc.)
  • The next 1 digit is for your module's major release version
  • The last 2 digits for sequential counting, starting with 01

Example:

example_update_9201(): The first update for the 9.x-2.x versions.
Where ‘example’ is the name of the module, the first digit refers to Drupal core version ‘9’, the number ‘2’ refers to the module’s major release version and the last two digits ‘01’ indicates the first update function written for module ‘example’.

The numeric part of the hook implementation function (i.e, 9201 in the above example) is stored in the database to keep track of which updates have already been executed. So you should never renumber update functions.
To know the current schema version of a module ‘example stored in database’, use:

drush php-eval "echo drupal_get_installed_schema_version(‘example’);"

Image removed.

 

To manually set the current schema version of a module ‘example’ back to ‘9201’, use:

drush php-eval "echo drupal_set_installed_schema_version('example', '9201');"

Image removed.

 

Note: Please try to avoid using  drupal_set_installed_schema_version() function on production sites as it directly updates your database. You can use it on your local or lower test environments during development to reset the schema version.

Add a proper description in the document block comment before the update hook function as it will be printed for the users while running it.

Structure of hook_update_N(): /**  * A aimple hook_update_N() hook.  */ function example_update_9201() {  // Code goes here. }

These hooks are executed in sorted order, i.e., example_update_9201() hook executes before example_update_9202(), next is 9203, 9204 and so on.

You can also change the sorted order of these hooks, by introducing dependencies between the hooks. Use the hook hook_update_dependencies() to run updates between two update hooks.

Image removed.

 

All the update hooks are executed in batch and they also support batch processing of items. All update hooks have access to a $sandbox parameter which can be used to create batch processes in the update hooks in order to process huge data at once without causing any PHP to timeout.

A simple example of an update hook to add a new configuration key:

Currently, the example_module.settings.yml file contains:

Image removed.

 

Image removed.

 

To add a new key ‘description’ to the configuration:

  • Add the ‘description’ key to the settings file
Image removed.

 

  • Add the update_hook in example_module.install file:
Image removed.

 

  • Use  drush updb to run the hook.
Image removed.

 

  • Check the updated configuration, the new key ‘description’ is updated.
Image removed.

Working with Post Update hooks

Hook hook_post_update_NAME(), similar to the update hook, is used to introduce an update. But this hook is mostly intended to update data, like entities. These hooks are executed after all the hook_update_N() hooks are run. At this stage, Drupal is already fully repaired so you can use any API within the site.

These hooks are placed in a *.post_update.php file in your module.

The hook_post_update_NAME()is written in the form of (module name)_post_update_(any name). Here NAME can be any arbitrary machine name. This alphanumeric naming of functions in the file is the only thing that ensures the execution order of this hook.

Similar to update hooks, add a proper description in the docblock comment before the post_update hook. Also, do not reuse the same hook name.

Structure of hook_post_update_NAME():

/**  * A aimple hook_post_update_NAME() hook.   */  function example_post_update_test() {   // Code goes here. }

Just like with update hooks, use the $sandbox parameter to indicate that the Batch API should be used for your post_update hooks.

A simple example on the usage of post-update hook to update the term data:

  • Currently, all the terms under Tags vocabulary have a disabled ‘Test example’ field.
Image removed.
  • Add a post_update hook in example_module.post_update.php file to enable the ‘Test example’ field for all the existing terms.
Image removed.

 

  • Use  drush updb to run the hook.
Image removed.

 

  • Verify the updated term data, the checkbox ‘Test example’ must be enabled.
Image removed.

How to Run these hooks!

You can use the Drush command to execute these hooks, drush updb.It builds the batch in the following steps:

  • All the update hooks are discovered.
  • Resolves dependency and sort their order.
  • Hooks are placed for batch processing.
  • Next, all the Post hooks are discovered.
  • If there are post_update hooks, and if update_hook has run previously, then caches are cleared.
  • Then, push each post_update hook into the batch.
  • Execute the batch.

One major advantage the post-update hook has over the update hook is that Drupal is fully functional at the time post-update is run. This allows developers to use any Drupal services while using the post-update hook. With the update hook, one must not assume that Drupal is fully repaired and avoid invoking other hooks, entity APIs, etc.

Final Thoughts

When trying to fix your site by updating config/database schema try to use update hooks. When comes to manipulating stored data, resaving configs, updating content entities, clearing the cache, etc then post-update hooks are more appropriate to use.

To be honest, there is no clear documentation on Drupal.org regarding when to use which hook! There is an open issue requesting to improve documentation on the usage of these two hooks to which you can contribute if you like.

But based on the developers' experience and by looking at the Drupal 9 & 10 core modules as an example, use update hooks to perform CRUD operations on configurations or databases (i.e repair the site) and use post-update hooks for CRUD content entities (then fix the data on the updated site), as post-update hooks are run after update hooks.

Enjoyed reading this article? Show us some love and subscribe to our weekly newsletter today!

Author: Ankitha Shetty

Meet Ankitha Shetty, a certified Drupal 9 developer. She loves attending and presenting at Drupal Camps and is a very active community member. Ankitha enjoys watching cricket and traveling to hill stations. Binge-watching web series is her current favorite pass time while she’s not cheering for her favorite cricket team :)

Email Address Subscribe Leave this field blank Drupal Drupal 9 Drupal 10 Drupal Development Drupal Planet

Leave us a Comment

 

Recent Blogs

Image Image removed.

Understanding Update and Post Update Hooks for Successful Site Updates

Image Image removed.

Embracing Achievements - Gagana Girish’s Living Dream

Image Image removed.

Data Security Matters: Marketers' Guide to Securing Your CMS

Want to extract the maximum out of Drupal? TALK TO US

Featured Case Studies

Image removed.Image removed.

Upgrading the web presence of IEEE Information Theory Society, the most trusted voice for advanced technology

Explore
Image removed.Image removed.

A Drupal powered multi-site, multi-lingual platform to enable a unified user experience at SEMI

Explore
Image removed.Image removed.

Great Southern Homes, one of the fastest growing home builders in the US, sees greater results with Drupal

Explore
View all Case Studies

Talking Drupal: Talking Drupal #396 - Drupal Security

Today we are talking about Drupal Security with Mark Shropshire & Benji Fisher.

For show notes visit: www.talkingDrupal.com/396

Topics
  • Why do you care about security
  • Best tips for securing Drupal
  • Common Security Issues people have with Drupal
  • Convincing module maintainers to do full releases
  • Testing to ensure security
  • Guardr Drupal security distribution
  • What does the Drupal Security team do
  • Finding issues
  • Review compromised sites
  • Becoming a member
  • Process for writing security notices
  • Helping the security team
Resources Guests

Benji Fisher - tag1consulting.com @benji17fisher Mark Shropshire - shrop.dev @shrop

Hosts

Nic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Jordan Graham - @jordanlgraham

MOTW Correspondent

Martin Anderson-Clutz - @mandclu CrowdSec Integrates your Drupal site with the open source CrowdSec Security Engine, a collaborative malicious activity detection and remediation tool.

The Drop Times: Listen, Learn, and Improve

Most of us want to be better versions of ourselves. Individuals, communities, organizations, and nations strive to progress in these changing times. However, it is not an easy task to achieve.

Progress comes through the knowledge of the present and a vision of the future. It begins with introspection. It requires one to point fingers at themselves rather than at others. It needs us to know our depths.

Apart from that, one needs to keep your eyes and ears open to new things. To new developments, new people, and new inspirations. Fresh water must keep flowing in to help a river do justice to its name.

A strong belief in our abilities must be at the heart of the journey forward. We must not forget who we are. We must not take our eyes off the goals that are there for us to achieve.

Progress isn’t a mechanical activity. Mind you; it won’t happen on its own. It awaits only mindful individuals or organizations that are self-aware. Open your eyes and ears. Humble yourselves to learn more. Above all, never let go of any chance to improve.

Now, let me walk you through the handpicked stories from the past week:

Drupal founder Dries Buytaert made some exciting announcements through his blog. Mautic, the marketing automation firm owned by Acquia, has now gone independent. Like Drupal, the community will drive its development. In another blog post, Dries disclosed the details of the Pitch-burgh contest that aims to encourage innovation. It will happen alongside DrupalCon Pittsburgh. Interestingly, Pitch-burgh is inspired by Shark Tank, the famous US TV show.

In another article published on opensource.com, Dries goes on to explain why it is essential to promote the Open-Web. Co-founder of PreviousNext, Owen Lansbury, has published a blog post on how a culture of open-source contribution helps his organization.

Aaron Winborn Award nominations are about to close. Do not forget to nominate Drupal community members who you think deserve the prize.

TDT conducted an in-depth interview with Jill Moraca. Princeton University’s Web Development Services Director responds to the questions posed by our Sub Editor, Alethia Rose Braganza.

We published a list of 5 YouTube videos for Drupal beginners. Another listicle presents 5 known Drupal modules you may not have installed.

Talking about security updates, two important ones were released last week. A new update to the DXPR theme helps its users comply with European privacy rules. Drupal has published a security update that clears an access bypass vulnerability.

Regarding Drupal events, DrupalCon Lille has released the last call for session submissions. Drupal Camp Asheville has extended the deadline to submit sessions. The Drop Times is now an official partner of the event.

The organizers of DrupalCamp Finland have published the final schedule. Those attending DrupalCamp Poland will get to explore Wrocław. The 2023 edition of MidCamp is set to begin on the 26th. The organizers of DrupalCamp Ruhr have designed Tshirts for the event on May.

Forms API helps to make forms in websites more enjoyable. Specbee has published a post on how to set up the same. Specbee also offers insights on how to use BEM methodology with Drupal and Data Security for Marketers who use CMS.

Velir has published a blog post on three new interesting modules for Drupal 10. Chapter Three shares information about hosting decoupled sites. LN Webworks has published a how-to guide on website personalization. Drupixels shares insights on the uses of the Automatic Entity Label module. OpenSense Labs writes about Drupal 10 Recipes.

A blog post published by Valuebound shows how to setup PHPUnit in Drupal 9 and 10. Opensources.com shared an article on how to use Autoloading and Namespaces in PHP. Drupal sites can now access Jonckers language services through a connector developed by the company.

A free webinar hosted by Drupal Partners will provide insights into Digital Marketing. Drupal Meetup at Zurich will discuss AI-powered search indexes and Splash Awards. The Drupal Bangalore User Group is all set to hold its monthly meetup on the 29th.

That’s all from the past week. We will update you with exciting stories from this week following Monday.

Sincerely,
Thomas Alias K
Sub Editor, TheDropTimes

LN Webworks: Why is Drupal the Perfect Choice for Building Mobile-Compatible Websites?

Smartphones have taken the world of the internet to a whole new sphere. Today, consumers can effortlessly access a plethora of websites anytime and from anywhere through their mobile phones. It is fascinating to note that mobile devices contribute to around 62% of all e-commerce traffic globally. Without expending much energy on thinking, we can easily figure out why this exactly happens. After all, we all are smartphone users. Whenever we find some time, the first thing we do is look at our mobile phones. Besides, a whopping 56% of people spend their daily free time shopping online through their smartphones.

LN Webworks: Challenges in Drupal Migration and How to Solve Them?

Nothing worthwhile comes easily. Work, continuous work, and hard work, is the only way to accomplish results that last.” - Hamilton Holt



Drupal has undeniably been the most eminent enterprise content management system (CMS) since its inception. Once it started its journey of customer acquisition, there was no looking back. Even today, Drupal enjoys the stature of being the most admired CMS in the world. One of the major factors that contribute to its immense success is the brand’s relentless pursuit to deliver unmatchable services to its clients. This bespeaks its customer-first approach. Every two-to-three years Drupal updates its systems to ensure cutting-edge security and top-notch features.