Skip to content

Instantly share code, notes, and snippets.

@simesy
simesy / mytheme.libraries.yml
Created March 3, 2024 01:55
Snapshot of tailwind config `npm ci` && `npm run build`
global-css:
version: 2
css:
theme:
dist/main.css: {}
global-js:
js:
dist/main.js: {}
dependencies:
@simesy
simesy / .gitignore
Last active November 3, 2023 07:52
Drop-in govcms PaaS settings.local.php and lando/ddev support
# Add to .gitignore.
.lando.yml
.ddev
.vscode
# Drush aliases can be used by anyone, but you might not want to add to repo.
# drush/sites/self.sites.yml
@simesy
simesy / google-script.js
Created December 28, 2022 02:05
Splat a 2-dim array of data into an existing sheet, resizing the sheet to match.
/**
* Wipe a sheet's data completely and replace it with new data.
*
* The method used will conserve the sheet itself along with
* properties of that sheet. Properties could include frozen rows
* and some named ranges.
*
* @param sheetName
* Name of the sheet (currently must exist).
* @param arrayOfArrays
@simesy
simesy / quick-drush-node-search.sh
Created February 9, 2021 11:31
One liner to find something in your node output
# If you want to find node pages with a string on them. Replace FINDME
# This is pretty intensive it will load and render all nodes in your site.
drush ev '$st = \Drupal::entityTypeManager()->getStorage("node"); $b= \Drupal::entityTypeManager()->getViewBuilder("node"); $ns = $st->loadMultiple(); foreach ($ns as $node) { print "FINDME " . $node->id() . "\n"; $built = $b->view($node, "default"); $o = \Drupal::service("renderer")->renderRoot($built); var_dump($o); }' | grep FINDME
@simesy
simesy / FooAccess.php
Last active February 6, 2021 00:50
Help user see webform subbissions with per-webform access. See https://www.drupal.org/project/webform/issues/3196440
<?php
// src/Access/FooAccess.php
namespace Drupal\foo\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\webform\Access\WebformEntityAccess;
use Drupal\webform\WebformInterface;
/**
* Implements hook_field_widget_form_alter().
*/
function mytheme_field_widget_form_alter(&$element, $form_state, $context) {
$plugin_id = $context['widget']->getPluginId();
$paragraph_type = isset($element['#paragraph_type']) ? $element['#paragraph_type'] : FALSE;
$parent_bundle = isset($element['#bundle']) ? $element['#bundle'] : FALSE;
$hidden_fields = [];
$group_links = FALSE;
@simesy
simesy / .gitconfig
Last active January 15, 2020 22:43
git config stuff
[alias]
co = checkout
br = branch
ci = commit
cp = cherry-pick
st = status
cor = !sh -c 'git fetch $1 $2 && git checkout $2' -
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
pushset = push --set-upstream origin
[core]
@simesy
simesy / config-export-http.sh
Last active December 6, 2019 04:44
Export remote config without drush or db.
#!/bin/bash
DOMAIN=${1:-"missing"}
if [[ ${DOMAIN} = "missing" ]] ; then
echo "Pass a Drupal site please, like https://example.com"
exit 1
fi
echo "What is your user name for ${DOMAIN}:"
read USER
@simesy
simesy / _notes
Last active December 11, 2019 07:37
local dev settings for drupal
These are not prod safe settings. Performance is not suitable for
general use.
Security or heavy performance things are commented out. You may want to
enable them manually.
To use, place these files in your sites/default/settings.php
should include the local.settings.php (if it exists). Then exclude
local.settings.* files in your .gitignore.
@simesy
simesy / gist:d66c49d43ae15603c7d9317973d14f6a
Last active December 3, 2019 04:38
notes for replacing a media with files
# Reges for finding drupal entities.
/<drupal-entity.*?data-entity-uuid="(.{36})">\s*?<\/drupal-entity>/
# raw data for command linking UUID with file
ahoy drush sqlq "SELECT m.mid as mid, m.uuid as uuid, mfd.status, f.fid as fid, f.filemime, f.filesize, f.filename, f.uri, mfd.name FROM media m INNER JOIN media_field_data mfd ON m.mid = mfd.mid INNER JOIN media__field_media_file mff ON m.mid = mff.entity_id INNER JOIN file_managed f ON mff.field_media_file_target_id = f.fid;"
# rough command
gsed -i -e s/PLACEHOLDER_12312312-1231-1231-1231-123123123123_PLACEHOLDER/"[<a href=\\\\\"\/sites\/default\/files\/SOMEFILE.pdf\\\\\">PDF: 8818 KB<\/a>]"/g ~/Backups/iwork.sql && echo "12312312-1231-1231-1231-123123123123"