Skip to content

Instantly share code, notes, and snippets.

@evolvingweb
evolvingweb / gist:2246159
Created March 30, 2012 03:16
hook_node_insert()
<?php
/*
* Implements hook_node_insert()
*
* Sends an email when a node is added
*/
function mail_node_insert($node) {
if ($node->type == "blog") {
mail('info@example.com', 'Blog Updated',
'Link: http://example.com/node/' . $node->nid);
@evolvingweb
evolvingweb / gist:2246154
Created March 30, 2012 03:14
hook_node_view()
<?php
/*
* Implements hook_node_view()
*
* Adds a note to each article node
*/
function mymodule_node_view($node, $view_mode) {
if ($node->type == 'article') {
$node->content['mymodule_note'] = array();
$node->content['mymodule_note']['#markup'] =
@evolvingweb
evolvingweb / gist:2244986
Created March 29, 2012 23:42
mymodule_node_list()
<?php
function mymodule_node_list() {
  $items = array(
    array('Suzanne'),
    array('Alex'),
    array('Tavish'),
    array('Thomas'),
  );
  //asks Drupal to render this as a list
  return array(
<?php
/*
* Implements hook_block_view().
*
* Displays an ad block.
*/
function mymodule_block_view($delta = '') {
  $block = array();
  switch ($delta) {
@evolvingweb
evolvingweb / gist:2243687
Created March 29, 2012 20:53
hook_block_info()
<?php
/*
* Implements hook_block_info()
*
* Adds a custom block
*/
function mymodule_block_info() {
$blocks['ad'] = array(
'info' => t('Advertisement'),
// DRUPAL_CACHE_PER_ROLE assumed
@evolvingweb
evolvingweb / ew_recent_nodes.module
Created March 29, 2012 20:42
Recent Nodes Module
<?php
/**
* Implementation of hook_init().
*
* Displays a diagnostic message to the user.
*/
function ew_recent_nodes_init() {
$message = t("The Recent Nodes module is enabled!");
drupal_set_message($message);
<?php
/**
* @file
* Implements a Solr proxy.
*
* Currently requires json_decode which is bundled with PHP >= 5.2.0.
*
* You must download the SolrPhpClient and store it in the same directory as this file.
*