Skip to content

Instantly share code, notes, and snippets.

@anotherjames
anotherjames / MySchemaFormBlock.php
Last active October 20, 2025 08:47
Config form from schema
<?php
namespace Drupal\MYMODULE\Plugin\Block;
use Drupal\Core\Block\Attribute\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
@anotherjames
anotherjames / phpmyadmin-search-filter.js
Created May 23, 2024 08:06
phpMyAdmin: Only show matches in string search results
jQuery('#searchresults').children('table').find('td:first-child').each(function () {
if (jQuery.trim(jQuery(this).text()).substring(0, 4) === '0 ma') {
jQuery(this).parent().remove()
}
})
@anotherjames
anotherjames / latinvalidation.module.php
Last active January 13, 2025 14:32
Drupal form element validation handler that checks a value is mostly Latin characters.
<?php
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterPluginCollection;
/**
* Implements hook_form_alter().
*/
function latinvalidation_form_alter(&$form, FormStateInterface $form_state, $form_id) {
@anotherjames
anotherjames / MyModuleCommands.php
Created December 22, 2023 15:14
Scan HTML in Drupal field values for elements & attributes used with text formats
<?php
namespace Drupal\my_module\Commands;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drush\Commands\DrushCommands;
/**
* Drush commands for my module.
@anotherjames
anotherjames / farmer.module.php
Last active July 14, 2020 11:11
Example Drupal 7 module for editing & translating a content type with hundreds of fields
<?php
/**
* @file
* Example Drupal 7 module for editing & translating a content type with
* hundreds of fields. See
* https://www.computerminds.co.uk/articles/editing-translating-over-100-fields
*/
/**
* Implements hook_module_implements_alter().