Skip to content

Instantly share code, notes, and snippets.



  • Digital Echidna
  • Canada
View GitHub Profile
Cottser / mytheme.theme.php
Created Mar 28, 2014
Adding template suggestions for view modes and content types in Drupal 8
View mytheme.theme.php
* Implements hook_theme_suggestions_HOOK_alter() for node.html.twig.
function MYTHEME_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// Add template suggestions based on the current view mode.
$node = $variables['elements']['#node'];
$suggestions[] = 'node__' . $variables['elements']['#view_mode'];
$suggestions[] = 'node__' . $node->bundle() . '__' . $variables['elements']['#view_mode'];
Cottser /
Last active Sep 5, 2019 — forked from dlo/
Python version of that pulls all bookmarks on the first sync, and does incremental updates afterwards. Updated to use Pinboard API token instead of password authentication.
#!/usr/bin/env python
This script is designed to generate a simple html file with _all_ of your bookmarks The HTML file can be added to Launchbar's index as a
custom bookmark file and you can search your entire collection
instantly from Launchbar (by title only). It includes any applied tags as part
of the title to aid in searching.
You should edit the `token`, `bookmark_filename`, and `local_timezone`
Cottser /
Last active Mar 8, 2019
Quick branch creation and patch applying
# Create or go to branch.
git go <name of branch>
# Apply the patch, commit with a commit message of "p".
cape && gcm p
Cottser / TweetsBlock.php
Created Jan 2, 2015
Example showing usage of the processed_text element in Drupal 8
View TweetsBlock.php
namespace Drupal\twitter_pull\Plugin\Block;
use Drupal\Core\Block\BlockBase;
* Provides a block for executing PHP code.
* @Block(
* id = "twitter_pull_tweets_block",
Cottser / Custom.css
Created Sep 27, 2011
IR_Black Theme (with sidebar and view-source colors) for Chrome Developer Tools
View Custom.css
/* IR_Black Skin by Ben Truyman - 2011
/* Based on Todd Werth's IR_Black:
/* Inspired by Darcy Clarke's blog post:
Cottser /
Last active Feb 7, 2016
xhprof-kit aliases and functions
# Creates a baseline from your current branch (should usually be 8.x).
alias bbranch='./xhprof-kit/ `git rev-parse --abbrev-ref HEAD`'
# Using the baseline xhprof identifier from the bbranch command above will benchmark 8.x against the baseline and your patched branch.
# e.g.
# bbranches [XHPROF-IDENTIFIER] [twig-branch-name-here-1234456]
function bbranches() {
originalbranch="$(git rev-parse --abbrev-ref HEAD)"
Cottser /
Last active Dec 23, 2015
Bash aliases for testing and applying patches based on the URL on your clipboard. If you're on OS X, grab the first three lines and add to your ~/.bash_profile. If you're on Linux, grab lines 5-8 and add to your ~/.bash_profile or ~/.bashrc or whatnot :)Testbot uses git to apply patches, I only include the `patch` version here because sometimes …
# These ones are for OS X.
alias cav='curl `pbpaste` | git apply -v --check'
alias capv='curl `pbpaste` | patch -p1 --dry-run'
# These are untested but should work on many flavours of Linux. If they don't,
# please leave a comment!
alias cav='curl `xsel --clipboard --output` | git apply -v --check'
alias capv='curl `xsel --clipboard --output` | patch -p1 --dry-run'
# Patch shortcuts (some duplication of the above, but covers more use cases).
Cottser /
Created Sep 3, 2013
Drupal 8 bash functions
# Clean up Drupal 8 installation and do a pull.
function cleand8() {
chmod u+w sites/default
git reset --hard
git checkout 8.x
git pull
sudo rm -rf sites/default/files/php
drush cc all
Cottser / module.module
Created Sep 26, 2011
Band-aid fixes for conflict between Block Title Link and Menu Block modules (D7)
View module.module
// Mini module to remove Block Title Link options from Menu Block blocks
function MODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'block_admin_configure') {
$module = $form['module']['#value'];
if ($module == 'menu_block') {
// remove fieldset
Cottser / block.tpl.php
Created Sep 23, 2011
HTML5 block-level links for Drupal 7 blocks
View block.tpl.php
<?php // Replace this: ?>
<?php print $content; ?>
<?php // With this: ?>
<?php if (isset($block->title_link)): ?>
<?php print l($content, $block->title_link, array('attributes' => array('title' => $block->title_link_title), 'html' => TRUE)); ?>
<?php else: ?>
<?php print $content; ?>
You can’t perform that action at this time.