aaron's blog

How to add cache-busting to itok image derivative urls in Drupal 7 for entity image fields

This will work to fool varnish caching of images. I wrote this because certain admins were not able to see their image derivatives immediately upon node save due to Varnish caching of the image urls. Installing the Varnish module was not possible due to hosting situation. This solution fixed the issue.

Remove the tabledrag from a field in Drupal using your theme

Tested in Drupal 8, probably works in Drupal 7 as well. Add the following to your theme's .theme file or template.php, based on drupal version.

Function to test for visible output in a render array

Here is a function to add to a Drupal theme that will return if a renderable array contains content. You can use this with an if statement to only include wrapper markup on content that actualy renders.

BASH find not finding all files

A painful discovery in the sense of time... the missing quotes on the following code was causing unexpected behavior when I was trying to locate files in BASH using find. When I did not have the double quotes around the -name option values, they were not functioning as wildcards as I'd expected.

This did not work:

files=$(find "," -name *.psp.md -or -name *.psp.txt -or -name *.psp.sh)

This did work:

files=$(find "." -name "*.psp.md" -or -name "*.psp.txt" -or -name "*.psp.sh") 

Code Snippet: How to use a field to control node access

Drupal 7 node access per entity using a field dropdown, callback functions and the node access API.

Regex for unbalanced anchor tag

Here is a regex expression for finding an unbalanced anchor tag in a chunk of text

if (preg_match_all('/<a\b[^>]*>(.*?)(?!<\/a>)/', $markup)) {
  // We found one or more, do something
Valid XHTML 1.0 Transitional