Sep 25, 2022

New! Drupal 9: Using Validation Constraints To Provide Custom Field Validations

Client requirements can be complex and those complex requirements often require custom code to be written. This includes making sure that the editing process conforms to certain validations.Drupal can easily handle simple validation like having a value in the field or making sure an email is valid, but with more complex validations usually require custom code.Whilst it is possible to inject custom validators into form submissions, I find using validation constraint classes makes the whole... more

Sep 18, 2022

New! Drupal 9: Debugging Cache Problems With The Cache Review Module

Drupal has a robust and dynamic cache system that allows complex pages to have different parts of it cached in different ways.Having a cache means that Drupal doesn't need to go back to the database and ask all the elements of the page to re-render everything for every page request. The results of the render can be stored in a cache and served much faster than having to recreate them again.You might have a page that displays content from a node and contains a few blocks to show menus,... more

Sep 11, 2022

New! PHP:CSI - To Switch, Or Not To Switch?

I was writing unit tests for a API mapping function recently and came across this interesting issue. The code I was writing tests for was in a legacy codebase that I was making changes to, and it made sense to have some unit tests in there before I started work to ensure everything worked before and after.The mapping function in question would take a value as input and return another value as the output. The code seemed like it should work, but then applying certain values to the mapping... more

Sep 04, 2022

New! Drupal 9: Generating Header Images For Pages Of Content Using PHP

Embedding image within pages of content helps both within the design of the page and when shared on social media. If you set up meta tags to point at a particular image then that image will appear when the page is shared on social media. This makes your page stand out more.A while ago I added a header image to the articles in the form of a field that references a media item, which is quite typical when adding images to pages. To add an header image to an article I just had to upload an image... more

Aug 28, 2022

New! Using PSR-4 With Composer

The PHP Standards Recommendations (called PSR) are a set of standards that aim to make certain aspects of working with PHP easier. They include things like coding standards (PSR-1), sending HTTP requests (PSR-7), and the autoloading standard PSR-4.PSR-4 describes the ability to include PHP classes based on their file paths. This means that instead of manually including every class file you need, you can write an autoloader that will do this for you.The key bits of information are the namespace... more

Aug 21, 2022

New! Drupal 9: Creating A Minimal Content Entity

I have recently been looking at generating custom content entities and this lead to generating a minimal entity that would be useful on a Drupal site.If you've ever used Drupal Console to generate a content entity, then you'll know what it generates a lot of files. There's all sorts of classes and configuration files generated that handle everything from generating lists of entities and forms for creating new entities.This got me thinking about what are the minimal about of... more

POPULAR
New! Drupal 9: Render A Drupal Page Within A Drupal Request
New! PHP:CSI - Date Is Less Than One Month Ago
New! Drupal 9: Adding Custom Plugins To The Session Inspector Module
New! Drupal 9: Creating A Block To Render A Node Field
New! Drupal 9: Programmatically Creating And Using URLs And Links