Skip to content

Instantly share code, notes, and snippets.

@williamluisi
williamluisi / gist:9062963
Created February 18, 2014 01:40
Function to find array key/value pair inside another array
<?php
/**
* Custom function to find an array key/value pair inside another array
*/
function _array_search($array, $key, $value) {
$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
@williamluisi
williamluisi / gist:7976189
Created December 15, 2013 18:13
check if current 'page' is a node type of blog
<?php
//check if pg is node
if (arg(0) == 'node') {
$nid = arg(1);
//load current node
if ($nid) {
$node = node_load($nid);
if($node->type == 'blog') {
@williamluisi
williamluisi / hook_block_list_alter_example.php
Created November 21, 2013 20:13
using hook_block_list_alter, programmatically hide/show a block on Views pgs and Node pages, based on if a flag field is set or not.
<?php
/**
* Implements hook_block_list_alter().
*/
function hook_block_list_alter(&$blocks) {
//dpm($blocks);
//check if pg is node
if (arg(0) == 'node') {
$nid = arg(1);
@williamluisi
williamluisi / hook_node_update_example.php
Last active December 29, 2015 00:49
Creates a taxonomy term from department $node->title values. Only when nodes are published.
<?php
/**
* Implementation of hook_node_update().
*/
function sas_health_custom_node_node_update($node) {
if ($node->type == 'department') {
//act on the unpublishing of a department.
if ($node->original->status == 1 && $node->status == 0) {
//
return $node;