Skip to content

Instantly share code, notes, and snippets.

View larowlan's full-sized avatar
:shipit:
Framework Manager, Drupal Core

Lee Rowlands larowlan

:shipit:
Framework Manager, Drupal Core
View GitHub Profile
/**
* Adds the default body field to a node type.
*
* @param $type
* A node type object.
* @param bool $subject
* (optional) Include a summary field. Defaults to TRUE.
* @param $label
* (optional) The label for the body instance.
*
@larowlan
larowlan / git-cleanup
Created June 14, 2013 01:31
Clean up old git branches
#!/bin/bash
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
git branch --merged master | grep -v 'master$' | xargs git branch -d
@larowlan
larowlan / d8aroo
Created June 14, 2013 01:39
Reinstall Drupal8 from one of three install locations /var/www/{d8|d82|d83}
#!/bin/bash
validTarget() {
if [ -z "$1" ]; then
echo "no arg"
return 1
fi
for i in d8 d82 d83
do
if [ $i == $1 ]; then
@larowlan
larowlan / die-defaults
Created June 18, 2013 03:04
Changes app/sites/default into a symlink
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage die-defaults site-name"
exit 1;
fi
if [ -d "./app/sites/$1" ]; then
if [ -d "./app/sites/default" ]; then
sudo rm -rf ./app/sites/default;
cd ./app/sites
ln -s $1 default
// Before.
$vars['foobar'] = array(
'#markup' => theme('yomamma', array('foo' => $foo, 'bar' => $bar);
);
// After.
$vars['foobar'] = array(
array(
'#theme' => 'yomamma',
'#foo' => $foo,
$node = node_load(1);
// I want field_foobar;
$value = FALSE;
if ($items = field_get_items('node', 'field_foobar')) {
$item = reset($items);
// A lot of fields use value, some use target_id, tid, it depends on their hook_field_schema.
// Good luck with that.
$value = $item['value'];
}
@larowlan
larowlan / drupal-7-blocks.php
Created January 7, 2014 22:02
Blocks before plugins
<?php
/**
* Implements hook_block_info().
*/
function forum_block_info() {
$blocks['active'] = array(
'info' => t('Active forum topics'),
'cache' => DRUPAL_CACHE_CUSTOM,
'properties' => array('administrative' => TRUE),
);
@larowlan
larowlan / ActiveTopicsBlock.php
Created January 7, 2014 22:09
Blocks as plugins
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Block\ActiveTopicsBlock.
*/
namespace Drupal\forum\Plugin\Block;
/**
@larowlan
larowlan / place_block.php
Created February 6, 2014 04:02
Place a block using update hook - Drupal 7
<?php
/**
* Place the views exposed search block.
*/
function YOURPROFILE_update_7001() {
$default_theme = variable_get('theme_default', 'YOURTHEME');
// Enable some standard blocks.
$blocks = array(
array(
'module' => 'views',
<?php
/**
* @file
* Contains \Drupal\system\Plugin\Block\SystemBrandingBlock.
*/
namespace Drupal\system\Plugin\Block;
use Drupal\block\BlockBase;