Skip to content

Instantly share code, notes, and snippets.

View markhalliwell's full-sized avatar
🦄
unicorns!

Mark Halliwell markhalliwell

🦄
unicorns!
  • Fort Worth, Texas, USA
View GitHub Profile
@markhalliwell
markhalliwell / menu-tree.vars.php
Last active August 29, 2015 14:04
Menu tree context alter
<?php
/**
* Implements hook_theme_registry_alter().
*/
function THEMENAME_theme_registry_alter(&$theme_registry) {
array_unshift($theme_registry['menu_tree']['preprocess functions'], 'THEMENAME_menu_tree_alter');
}
/**
* Helper function for adding the tree context to the variables.
<?php
$items = array();
$build['list'] = array(
'#theme' => 'item_list',
'#items' => $items,
'#empty' => t('You have no content, please <a href="!link">create some</a>.', array(
'!link' => 'node/add',
),
@markhalliwell
markhalliwell / stark2.theme.php
Created July 8, 2014 15:45
Adding external/inline resources via #attached in a Drupal 8 theme
<?php
/**
* @file
* Example of how to attach external and inline resources for a theme via the
* #attached render array method in 8.x.
*/
/**
* Helper function for attaching resources to a render array.
*/
{% attributes.class.add([
'node',
'node--type-' ~ node.bundle|class,
node.promoted ? 'node--promoted',
node.sticky ? 'node--sticky',
not node.published ? 'node--unpublished',
preview ? 'node--preview',
'node--view-mode-' ~ view_mode|class
]).remove([
'some-module-class'
@markhalliwell
markhalliwell / 1-issue.comments.alter.js
Last active August 29, 2015 13:56
Issue comments alter
/**
* THIS FILE ALTERS ANY ISSUE WITH THE NEW STYLING. IT AUTOMATICALLY INCLUDES THE CSS FILE
* BELOW. JUST COPY AND PASTE THIS IN YOUR INSPECTOR CONSOLE.
**/
(function ($) {
var localStorageSupported = false;
var enableTimeago = false;
// Only enable timago if user's browser has localStorage support (so they can
// double click to enable and disable at will).
if (typeof window.localStorage !== 'undefined') {
<?php
return array(
'#theme' => 'table__forum_list',
'#theme_wrappers' => array('container__suggestion'),
'#attributes' => array(
'class' => array('extra-class', 'even-more-classes'),
'id' => 'i-am-unique',
'data-toggle' => 'tooltip',
),
@markhalliwell
markhalliwell / post-commit
Last active December 22, 2015 12:29
Drupal project post commit (copies thanks and commit link to pasteboard). Follow instructions at https://coderwall.com/p/jp7d5q
#!/bin/sh
# Ensure repo is hosted on drupal.org.
repoRemote=`git remote -v | grep push | perl -lne 'print $& if /git\.drupal\.org[:\/]project\/[^.]*/'`;
if [ ! -z "${repoRemote}" ]; then
# Extract the project and commit info.
project=`echo "${repoRemote}" | sed -e 's/git\.drupal\.org[:\/]//'`;
commitHash=`git log -n 1 --pretty=format:"%h"`;
commitName=`git log -n 1 --pretty=format:"%cn"`;
commitMessage=`git log -n 1 --pretty=format:"%B"`;
@markhalliwell
markhalliwell / theme.php
Last active December 20, 2015 11:39
Here's my "vision" on seeing the potential of what the theme system _could_ be.
<?php
// We implment something like hook_element_info() for themes.
// In theory, this identical to hook_theme(), but doesn't require
// a registry.
function system_theme_info() {
$info['foo_bar'] = array(
'variables' => array('title' => NULL, 'content' => NULL),
'context' => array('conditional_switch' => FALSE),
// Blah blah blah, rest of hook code.
<?php
function MODULE_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node'] && !empty($form['#node_edit_form'])) {
$node = $form['#node'];
$action = in_array('add', args()) ? t('Create new') : t('Edit existing');
switch ($node->type) {
case 'article': drupal_set_title(t('!action basic article', array('!action' => $action))); break;
case 'blog': drupal_set_title(t('!action blog article', array('!action' => $action))); break;
case 'audio': drupal_set_title(t('!action audio conent', array('!action' => $action))); break;
@markhalliwell
markhalliwell / perm.sh
Created July 21, 2013 16:53
Change the ownership settings according to how your www environment is setup.
#!/bin/bash
echo 'Setting ownership to _www:staff ...';
sudo chown -R _www:staff ./;
echo 'Setting directory permissions to 0755 ...';
sudo find . -type d -exec chmod u=rwx,g=rwx,o=rx '{}' \;
echo 'Setting file permissions to 0644 ...';
sudo find . -type f -exec chmod u=rw,g=rw,o=r '{}' \;