Articles tagged with code example

How to implement File Validation events?

Posted on
Drupal 11 will change many functionality related to file validation. One of the changes is the hook_file_validate() which is now deprecated and will be removed from Drupal 11.

Show field on entity form programmatically

Posted on
How do you update entity display mode to show a newly created field by default? It is easy with configuration import, but what if you need to use hook_update_N?

Importing translations in Drupal

Posted on
Drupal has good multilingual support out of the box and it allows to creation of multilingual sites easily. In normal circumstances translation process is easy, but there are some cases where you may want to update translations programmatically.

PHP enum values as an array keys

Posted on
Enums allow a developer to define a custom type that is limited to one of a discrete number of possible values. Using it as an array key was not that straightforward.

Backup website database to Google Drive

Posted on
I needed a basic solution to back up the website database into Google Drive, just to have some backups in case something bad happens.

Entity query parameters are language dependent

Posted on
I have worked on multilingual Drupal sites quite a lot but some things still come as a surprise. I have used entity query in some cases but today I did encounter an issue where something did not work correctly.