Skip to content

Instantly share code, notes, and snippets.

View markfullmer's full-sized avatar

Mark Fullmer markfullmer

View GitHub Profile
@markfullmer
markfullmer / nominalDrupal11.php
Last active March 21, 2024 20:40
Make all Drupal modules nominally Drupal 11 compatible
<?php
// @codingStandardsIgnoreFile
// NOTE: THIS CAN BE ACHIEVED WITH drupal/backward_compatibility
function find_info_files($dir) {
$root = scandir($dir);
$result = [];
foreach ($root as $value) {
if ($value === '.' || $value === '..') {
continue;
@markfullmer
markfullmer / Defuser.php
Last active December 21, 2022 16:18
Remediate inline blocks referenced by multiple node layouts (entity_clone)
<?php
namespace Drupal\mymodule;
use Drupal\layout_builder\Section;
/**
* Resave inline blocks associated with cloned nodes.
*/
class Defuser {
@markfullmer
markfullmer / Enhancer.php
Created October 28, 2021 15:44
Set Drupal View to be used per taxonomy vocabulary
<?php
namespace Drupal\mymodule\Enhancer;
use Drupal\Core\Routing\EnhancerInterface;
use Drupal\taxonomy\TermInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Drupal\taxonomy\Entity\Term;
@markfullmer
markfullmer / convertfoundationAccordion.php
Last active October 6, 2021 18:40
Convert Zurb Foundation Accordion to generic details/summary using DomDocument
<?php
$input = 'Some text<a href="#">Test</a><ul class="accordion" data-accordion role="tablist">
<li class="accordion-navigation" role="presentation">
<a href="#panel1d" role="tab" id="panel1d-heading" aria-controls="panel1d">Accordion 1</a>
<div id="panel1d" class="content active" role="tabpanel" aria-labelledby="panel1d-heading">
Panel 1. Lorem ipsum dolor
</div>
</li>
<li class="accordion-navigation" role="presentation">
@markfullmer
markfullmer / deduplication.sql
Created August 8, 2020 18:58
SQL query to find duplicates in a table
SELECT `title`, COUNT(`title`) FROM `node_field_data` GROUP BY `title` HAVING COUNT(`title`) > 1
// https://www.sqlservertutorial.net/sql-server-basics/sql-server-find-duplicates
@markfullmer
markfullmer / .bash_git_prompt
Last active May 31, 2020 16:51
Bash Git Prompt showing dirty state & branch
# Detect whether the current directory is a git repository.
function is_git_repository {
git branch > /dev/null 2>&1
}
function parse_git_dirty {
[[ -z $(git status --porcelain) ]] || echo "*"
}
function parse_git_branch {
# Set the BRANCH variable.
@markfullmer
markfullmer / find_replace.sh
Last active May 20, 2020 19:18
Simple bash find-replace using "rename"
rename 's/utprof_/pharm_/' *
# For OS X, GNU rename can be installed using homebrew: brew install rename.
@markfullmer
markfullmer / aliases.sh
Created May 7, 2020 21:09
Time-saving alias for auto-triggering a browser opening of `drush uli`, via Docksal: alias fuli='open $(fin uli)'
alias fuli='open $(fin uli)'
@markfullmer
markfullmer / cr.sh
Created May 7, 2020 20:38
Fast Drupal 8+ cache rebuild Docksal command
#!/usr/bin/env bash
#: exec_target = cli
# PROJECT_ROOT and DOCROOT are set as env variables in cli
SITE_DIRECTORY="default"
DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"
mysql --user="$MYSQL_USER" --database="$MYSQL_DATABASE" --password="$MYSQL_PASSWORD" -e "SHOW TABLES LIKE 'cache%'" | tail -n +2 | xargs -L1 -I% echo "TRUNCATE TABLE %;" > cache-tables.txt