Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active December 10, 2015 06:28
Show Gist options
  • Save cesarmiquel/4394758 to your computer and use it in GitHub Desktop.
Save cesarmiquel/4394758 to your computer and use it in GitHub Desktop.
This are drupal snippets I constantly use in my modules. Replace xxxxx with module name.
<?php
/**
* Implements hook_menu().
*/
function xxxxx_menu() {
$items['path'] = array(
'title' => '[Title]',
'access callback' => TRUE,
'page callback' => 'xxxxx_render_page',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_theme().
*/
function xxxxx_theme() {
return array(
'xxxxxx_block' => array(
'variables' => array('node' => array()),
'template' => 'theme/xxxxxx-block',
),
'node__[content-type]' => array(
'variables' => array('node' => array()),
'template' => 'theme/node--[content-type]',
),
);
}
/**
* Implements hook_preprocess_node().
*/
function xxxxx_preprocess_node(&$vars) {
// pre-process code here...
$node = $vars['node'];
// do stuff...
}
/**
* Implements hook_block_info().
*/
function xxxxx_block_info() {
$blocks = array();
$blocks['delta'] = array('info' => '[descrition]');
return $blocks;
}
/**
* Implements hook_block_view().
*/
function xxxxx_block_view($delta = null) {
$block = array(
'subject' => '[block title]',
'content' => '[block html or render array]',
);
return $block;
}
/**
* Implements hook_views_api()
*/
function xxxxx_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'xxxxx') . '/views',
);
}
// ======================================================================
// content of: sites/all/modules/custom/xxxxx/views/xxxxx.views.inc
// ======================================================================
/**
* Implements hook_views_default_views()
*/
function xxxxx_views_default_views() {
$views = array();
/* paste view code here ---------------------------------------------------- */
/* .... */
/* end view code here ---------------------------------------------------- */
$views[$view->name] = $view;
return $views;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment