Skip to content

Instantly share code, notes, and snippets.

@mikohl
mikohl / drupal-update-filter-bookmarklet.js
Last active June 14, 2024 18:28
Hides all the up-to-date modules on the Available updates page so you can easily see what needs to be updated. To use this, create a new bookmark in your browser and past the code from the drupal-update-filter-bookmarklet.js file into the URL field.
javascript:(()%3D%3E%7B!function()%7Bwindow.drupUpdateFormClose%3Dfunction()%7Bvar%20e%3Ddocument.getElementById(%22drupUpdateStatusForm%22)%3Bnull!%3D%3De%26%26e.remove()%7D%2Cwindow.drupUpdateStatusClear%3Dfunction()%7BObject.values(document.querySelectorAll(%22.update%22)).forEach((e%3D%3E%7BObject.values(e.querySelectorAll(%22tr%22)).forEach((e%3D%3E%7Be.style.display%3D%22block%22%7D))%7D))%7D%2Cwindow.drupUpdateStatusShowAll%3Dfunction()%7BdrupUpdateStatusClear()%2CObject.values(document.querySelectorAll(%22.update%22)).forEach((e%3D%3E%7BObject.values(e.querySelectorAll(%22.ok%2C%20.color-success%22)).forEach((e%3D%3E%7Be.style.display%3D%22none%22%7D))%7D))%7D%2Cwindow.drupUpdateStatusShowSecurity%3Dfunction()%7BdrupUpdateStatusClear()%2CObject.values(document.querySelectorAll(%22.update%22)).forEach((e%3D%3E%7BObject.values(e.querySelectorAll(%22.ok%2C%20.color-success%2C%20.warning%2C%20.unknown%2C%20.color-warning%22)).forEach((e%3D%3E%7Be.style.display%3D%22none%22%7D))%7D))%7D%2CdrupUpdateFormClo
@mikohl
mikohl / custom.module
Last active May 23, 2024 13:48
A client needed a "Last Updated" field that they could set manually, to show if and when a blog article had been revised. They did not want to use the Revised date because they didn't want to have the date change for minor edits, such as typo fixes.
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;
/**
* Implements hook_views_query_alter().
*/
function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ($view->id() == 'view_id') {
// Use the publish date or last updated field to sort for all blog listing views.
$query->addField(
@mikohl
mikohl / field_length.install
Last active April 4, 2025 15:32
Site was built using a text field for URLs which was capped at 255 characters. Users found that embedding from some external services required many parameters and quickly exceeded that limit. This updates the field configuration and the database schema to 2048 characters.
<?php
/**
* @file
* Contains field_length install and update hooks.
*/
declare(strict_types=1);
use Drupal\Core\Utility\UpdateException;