Skip to content

Instantly share code, notes, and snippets.

View bdlangton's full-sized avatar

Barrett Langton bdlangton

View GitHub Profile
@bdlangton
bdlangton / drupal_mail
Created July 20, 2016 15:21
Set smtp mail system enabled w/maillog. Disable sending emails, but log them.
# Put in settings.php.
$conf['mail_system'] = array('default-system' => 'SmtpMailSystem');
$conf['smtp_deliver'] = '1';
$conf['maillog_devel'] = '1';
$conf['maillog_log'] = '1';
$conf['maillog_send'] = '0';
$conf['maillog_engine'] = 'SmtpMailSystem';
@bdlangton
bdlangton / README.md
Last active June 1, 2022 19:13
Git hooks

Install required packages

Install the packages that you'll need. Drupal/coder includes phpcs. If you're not wanting to use a specific hook, then you don't need to install the associated packages.

composer global require drupal/coder phpmd/phpmd sebastian/phpcpd

Set path

Set the path in your shell startup script (ex: .zshrc or .bashrc).

@bdlangton
bdlangton / phpcs.txt
Last active May 27, 2022 00:49
phpcs config-set for Drupal using Coder module
# Basic default configs.
phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
phpcs --config-set default_standard Drupal
phpcs --config-set colors 1
# Show all errors.
phpcs --config-set error-severity 1
# Shows warnings, but doesn't return a non-zero return.
phpcs --config-set ignore_warnings_on_exit 1
@bdlangton
bdlangton / gist:f2ad5b4c06755a7f025ebfafdb6d0cae
Last active December 12, 2016 22:34
Print out db_select/views final query for debugging
// Print out query built by views:
// Can use pre_execute or post_render (probably more also).
function hook_views_pre_execute(&$view) {
dpq($view->build_info['query']);
}
// Print out query build by db_select:
dpm((string) $query);
dpm($query->arguments());
@bdlangton
bdlangton / update-hooks
Created September 22, 2016 21:45
Clears out current git hooks and runs 'git init' to apply hooks that are in .git-templates/hooks
#!/usr/bin/env bash
# Check that the git directory exists.
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ -z "$GIT_DIR" ]; then
echo >&2 "Fatal: GIT_DIR not set"
exit 1
fi
# Remove existing hooks and re-init to copy new hooks.
@bdlangton
bdlangton / bootstrap.inc
Last active March 4, 2020 22:46
Drupal: dpm backtrace any errors
// This function exists in includes/bootstrap.inc.
// Just need to add lines 6-7 to it.
function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
require_once DRUPAL_ROOT . '/includes/errors.inc';
$d = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
dpm($d, $message);
_drupal_error_handler_real($error_level, $message, $filename, $line, $context);
}
@bdlangton
bdlangton / custom.settings.php
Last active May 16, 2017 19:38
Development settings for Drupal 7
// My custom settings.
// Show all errors.
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
// Show Views SQL query and performance stats in preview. Requires: views_ui.
$conf['views_ui_show_sql_query'] = 1;
$conf['views_ui_show_performance_statistics'] = 1;

Show number of commits per author.

git shortlog -sn --all

Use --no-merges if you want to exclude merge commits Use -e if you want to see the users' email addresses

Get list of contributors for the repo.

git log --format='%aN' | sort -u

@bdlangton
bdlangton / .gitconfig
Created November 28, 2017 02:58
Sample gitconfig
[user]
name = Barrett Langton
email = barrett@example.com
[core]
editor = vim
filemode = false
[merge]
tool = vimdiff
[alias]
br = branch
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');