Skip to content

Instantly share code, notes, and snippets.

View krisahil's full-sized avatar

Chris Hill krisahil

View GitHub Profile
@krisahil
krisahil / modules_info.sh
Created March 18, 2014 14:24
List info about all contrib modules available on a Drupal site.
#!/bin/bash
tmp="/tmp/temp-file"
alias=""
# List all contrib modules.
for name in $(drush $alias sql-query "SELECT name FROM system WHERE type = 'module' AND filename LIKE 'sites/all/modules%'"); do
# Skip header row.
if [[ "name" == $name ]]; then
continue
@krisahil
krisahil / gist:11057840
Last active September 18, 2020 15:39
Drupal 6: Export all fields and their content types to CSV
<?php
$content_types = node_get_types();
$header = array(
'Source content type',
'Source content type machine name',
'Source field name',
'Source field machine name',
);
$sql_field_type_collector = "
@krisahil
krisahil / mkdocs-drupal-7-integration.md
Last active January 27, 2023 12:05
MkDocs served via Drupal 7 private file system

MkDocs is a great documentation framework, and Drupal is a great backend CMS. While you can use Drupal's hook_help(), if you have a lot of application-specific documentation, you may want to use a dedicated documentation tool. But how to integrate the documentation into the CMS?

I wanted a solution which would:

  • Use the same Git repository for docs (e.g., for MkDocs) as for Drupal. Being on the same repository ensures that we can write docs for MkDocs as we also write code for Drupal.
  • Commit only the docs source to Git, not the compiled docs from MkDocs
    • This means the docs would need to be compiled and then deployed to the production server.
  • Protect the compiled docs behind user access. Ideally, could use Drupal user system to only allow access to specific users.

We tried a few approaches, but each violated the above rules. Then someone suggested using Drupal's private file system ("private://") to control access. This actually worked! Here is the overview of how we se

@krisahil
krisahil / check_ips_for_googlebot.sh
Last active September 30, 2019 20:52
Check IPs for Googlebot
#!/bin/bash
if [ ${#} -lt 1 ]; then
>&2 echo "Usage: $0 [input .jsonl file]"
>&2 echo "Example: $0 export.jsonl"
exit 1
fi
input_file="$1"
output_file="ip_addresses.txt"
@krisahil
krisahil / composer_diff_as_csv.sh
Created January 19, 2024 16:50
Convert "composer diff" output to CSV
#!/bin/bash
# Converts the JSON from `composer diff` to CSV rows, filtered for only
# Drupal-related projects.
# Here's what this script does, line by line:
# 1) Runs `composer diff` for the current code against latest `develop` branch.
# 2) Skips the first line, because I can't figure out how to suppress it (on my
# local, the line is: `ComposerInContainer\Composer\ScriptHandler::preInstallUpdateCommand`.
# 3) Grabs the `packages` list, which is the prod packages list. Converts each
@krisahil
krisahil / mymodule.info.yml
Last active March 25, 2024 18:26
Drupal: Form mode switcher for imported content
name: 'mymodule'
type: module
description: 'Demo module to show how to switch form modes for imported/migrated content'
package: Custom
core_version_requirement: ^10
dependencies:
- drupal:migrate