Skip to content

Instantly share code, notes, and snippets.

View joakim's full-sized avatar
🌿

joakim

🌿
View GitHub Profile
@joakim
joakim / path_save_subpage_alias.php
Last active December 25, 2015 18:49
Drupal: Save additional path aliases for subpages. Could be used with nodes to make node/123/edit (with alias "foo") look like foo/edit. Prettier.
/**
* Implements hook_node_presave().
*/
function custom_node_presave($node) {
// Get the source of the "base" path which has subpages.
$source = 'node/' . $node->nid;
// If the node's alias is "foo", foo/edit will be an alias for node/123/edit.
custom_save_subpage_alias($source, 'edit');
@joakim
joakim / taxonomy_term_remove_from_nodes.php
Created October 16, 2013 10:05
Drupal: Programmatically remove a term from multiple nodes
// ID of taxonomy term to remove.
$tid = 5;
// Name of the taxonomy field where the term is found.
$field_name = 'field_NAME';
_taxonomy_term_remove_from_nodes($tid, $field_name);
function _taxonomy_term_remove_from_nodes($tid, $field_name) {
$nids = taxonomy_select_nodes($tid, FALSE, FALSE);
# Configure colors, if available.
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
c_reset='\[\e[0m\]'
c_user='\[\033[1;33m\]'
c_path='\[\e[0;33m\]'
c_git_clean='\[\e[0;36m\]'
c_git_dirty='\[\e[0;35m\]'
else
c_reset=
c_user=
@joakim
joakim / gist:996820
Created May 28, 2011 12:09
nginx configuration of site where changes to static files aren't reflected through nginx
server {
server_name foo;
listen 80;
error_log /var/log/nginx/foo.error;
access_log /var/log/nginx/foo.access main;
root /srv/www;
location ~* \.(png|jpg|jpeg|gif|ico)$ { # TODO Add CSS and JS to the mix for production
@joakim
joakim / Vagrantfile
Created January 25, 2011 14:00
Using files from /vagrant as /var/www
Vagrant::Config.run do |config|
(…)
# Share project folder through NFS.
config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
# Provisioning.
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"