Skip to content

Instantly share code, notes, and snippets.

@joachim-n
joachim-n / gist:70f6be48dde515031e5404d00fbd2dea
Created September 21, 2026 17:11
importing config in kernel test such that ConfigEvents::STORAGE_TRANSFORM_IMPORT is triggered - DOES NOT WORK!
$active_storage = $this->container->get('config.storage');
$sync_storage = $this->container->get('config.storage.sync');
// Copy config to sync to simulate a config export.
$this->copyConfig($active_storage, $sync_storage);
// Import config. We have to do the transform ourselves, because the core
// config system doesn't trigger the transformation event ConfigEvents::STORAGE_TRANSFORM_IMPORT from the API.
// See https://www.drupal.org/project/drupal/issues/3619723.
// Do the transformation ourselves.
@joachim-n
joachim-n / gist:d67972e42bb00c3b76d5ede99de07044
Created September 11, 2026 10:22
get all gitlab issues you're participating in
<?php
/**
* Show a table of all issues you're participating in.
*
* This aims to replicate the list of current issues on d.org.
*
* To be 'participating' in a gitlab issue, leave an emoji on it.
*/
@joachim-n
joachim-n / KernelTestWithMockedClientRequestsExampleTest.php
Created June 18, 2024 09:14
Mocking Guzzle to handle client requests in a test
<?php
namespace Drupal\Tests\external_entities\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\RequestInterface;
@joachim-n
joachim-n / gist:a75ceed3186d63dc2a13e66bc799596d
Created March 26, 2024 13:51
inline call for loop list vs variable assignment
<?php
// THIS DOESN'T WORK!
// SOME WEIRD INTERNAL CACHING IS HAPPENING - whichever is executed second
// is faster!
function getLoopList() {
return range(1, 10);
}
@joachim-n
joachim-n / gist:4f1c046d61a68384c416eb806a904249
Created December 1, 2023 10:25
Script for switching a project to use a git clone of a Drupal contrib module
#!/usr/bin/env bash
# Script for switching a project to use a git clone of a Drupal contrib module.
if [ ! -d repos/$1 ]; then
# Get the version of the module that the project currently has installed
# so we can clone the same version. This ensures that Composer will accept to
# install it.
VERSION=`php -r "require_once 'vendor/autoload.php'; print \Composer\InstalledVersions::getReference('drupal/$1');"`
@joachim-n
joachim-n / gist:56e37400a7e953c2d2015d342716f783
Created November 29, 2023 11:04
Mock discovery in plugin manager
<?php
namespace Drupal\Tests\list_predefined_options\Kernel;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\list_predefined_options\ListOptionsManager;
@joachim-n
joachim-n / kernel test form submission
Created April 7, 2023 12:33
Make a POST request to a form
/**
* Make a POST request to a form.
*
* @param string $url
* @param array $data
*/
protected function doPostForm(string $url, array $data = []) {
$request = Request::create($url);
$response = $this->doRequest($request);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
public static function check($checking_key, $data) {
try {
serialize($data);
}
catch (\Throwable $e) {
// The data fucked up. Go into it to see where.
ddm("CATCH $checking_key");
if (is_array($data)) {
foreach ($data as $key => $val) {
static::check($key, $val);
@joachim-n
joachim-n / dashcam-blank.js
Created July 10, 2022 20:51
Bookmarklet for filling in Dashcam submission form
// Fill in the details with your own.
// Paste this as the URL of a new Firefox bookmark.
// Use the bookmark when on https://secureform.nextbase.co.uk/
javascript: {
document.getElementById('signature').value = '';
document.getElementById('name').value = '';
// Doesn't work yet.
// document.getElementById('preferredContact').value = '0';
document.getElementById('email').value = '';
document.getElementById('phone').value = '';
#!/usr/bin/perl -p
# show what the hell is happening with line endings
s[ (?<! \r ) \n ]
[UNIX\n]x;
s[ \r\n]
[WIN\n]x;