Debugging Drupal Commerce Promotions and Adjustments using Illuminate Collections (Drupal 8)
Today I found another instance where I decided to use Illuminate Collections within my Drupal 8 code; whilst I was debugging an issue where a Drupal Commerce promotion was incorrectly being applied to an order.Read more about Debugging Drupal Commerce Promotions and Adjustments using Illuminate Collections (Drupal 8)
Quick Project Switching in PhpStorm
Following a recent conversation on Twitter with socketwench about project switching in PhpStorm, I thought I’d document my workflow here.Read more about Quick Project Switching in PhpStorm
Examples of using Laravel Collections in Drupal
Since starting to work with Laravel as well as Drupal and Symfony, watching Adam Wathan’s Refactoring to Collections course as well as lessons on Laracasts, I’ve become a fan of Laravel’s Illuminate Collections and the object-orientated pipeline approach for interacting with PHP arrays.
I’ve also tweeted several examples of code that I’ve written within Drupal that use Collections, and I thought it would be good to collate them all here for reference.Read more about Examples of using Laravel Collections in Drupal
Experimenting with events in Drupal 8
I’ve been experimenting with moving some of the code to Drupal 8, and I’m quite intrigued by a different way that I’ve tried to structure it - building on some of the takeaways from Drupal Dev Days.Read more about Experimenting with events in Drupal 8
Null Users and System Users in Drupal
Have you ever needed to have a 'special user' to perform tasks on your Drupal site, such as performing actions based on an API request, or for sending an internal site message?
If you just create a new user, how do you identify that user going forward? Do you hard-code the 'magic' user ID in your custom code? What if the user has a different ID on different environments of your site? You could declare it in each environment’s settings file and retrieve it from there, but what then if you need to do the same on another site? That would mean some duplication of code - and something that could have been abstracted and re-used.
I had to do this recently, and rather than just duplicate the code I decided to make it into it’s own module - which then became two modules.Read more about Null Users and System Users in Drupal
Drupal 8 Commerce: Fixing 'No Such Customer' error on checkout
Recently I was experiencing an issue on the Drupal 8 website I’m working on, where a small number of users were not able to complete the checkout process and instead got a generic
The site has encountered an unexpected errormessage.
Looking at the log, I was able to see the error being thrown (the customer ID has been redacted):Read more about Drupal 8 Commerce: Fixing 'No Such Customer' error on checkout
Croeso PHP South Wales!
Last night was the first meetup of Cardiff’s PHP South Wales user group! It was a great first event, and it was great to meet a lot of new people as well as catch up some familiars within the 36 (according to meetup.com) attendees - including some PHP South West regulars.Read more about Croeso PHP South Wales!
How to run Drupal 8 PHPUnit Tests within Docksal from PhpStorm
I’ve recently re-watched A Clean PHPUnit Workflow in PHPStorm on Laracasts, where Jeffrey configures PhpStorm to run tests from within the IDE. With Drupal 8 using PHPUnit too, I decided to try and do the same with a local D8 site.
Though because I’m using Docksal for my local development environment which, at least on a Mac, runs Docker containers within a virtual machine, there were some additional steps needed to achieve this and to have the tests run within the Docksal virtual machine and using the correct containers.Read more about How to run Drupal 8 PHPUnit Tests within Docksal from PhpStorm
Drupal Bristol Testing Workshop
Yesterday evening, I did my first workshop (and I believe, the first workshop) held at the Drupal Bristol user group. The subject was automated testing with PHPUnit in Drupal 8, in preparation for my talk at Drupal Developer Days 2018 next week and to help process some ideas for my testing book.
Here are some details about what we covered, and some of my thoughts in review.Read more about Drupal Bristol Testing Workshop
How to Use Environment Variables for your Drupal Settings with Docksal
Within the Docksal documentation for Drupal settings, the example database settings include hard-coded credentials to connect to the Drupal database. For example, within a
settings.phpfile, you could add this:
$databases['default']['default'] = [ 'driver' => 'mysql', 'host' => 'db', 'database' => 'myproject_db', 'username' => 'myproject_user', 'password' => 'myproject_pass', ];
Whilst this is fine, it does mean that there is duplication in the codebase as the database credentials can also be added as environment variations within
.docksal/docksal.env- this is definitely the case if you want to use a custom database name, for example.
Also if one of these values were to change, then Drupal wouldn't be aware of that and would no longer be able to connect to the database.
It also means that the file can’t simply be re-used on another project as it contains project-specific credentials.
We can improve this by using the environment variables within the settings file.Read more about How to Use Environment Variables for your Drupal Settings with Docksal