Skip to content

Instantly share code, notes, and snippets.

View maciejzgadzaj's full-sized avatar

Maciej Zgadzaj maciejzgadzaj

View GitHub Profile
@maciejzgadzaj
maciejzgadzaj / gist:1061609
Created July 2, 2011 20:22
hook_admin_paths() implementation
<?php
/**
* Implements hook_admin_paths().
*/
function MYMODULE_admin_paths() {
$paths = array(
'terms-and-conditions' => TRUE,
);
return $paths;
@maciejzgadzaj
maciejzgadzaj / gist:1061604
Created July 2, 2011 20:14
hook_menu: definition of Terms & Conditions page.
<?php
/**
* Implements hook_menu().
*/
function MYMODULE_menu() {
$items = array();
$items['terms-and-conditions'] = array(
'title' => t('Terms & Conditions'),
'page callback' => 'MYMODULE_page_terms_and_conditions',
<?php
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register_form') {
$form['#validate'][] = 'MYMODULE_user_register_form_validate';
}
}
<?php
/**
* Additional handler for user_login form submit.
*/
function MYMODULE_user_login_submit($form, &$form_state) {
$user = user_load($form_state['uid']);
if ($user->access == 0) {
$form_state['redirect'] = 'terms-and-conditions';
}
@maciejzgadzaj
maciejzgadzaj / gist:1055124
Created June 29, 2011 22:01
Adding own extra submit function using Drupal's hook_form_alter
<?php
/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_login') {
$form['#submit'][] = 'MYMODULE_user_login_submit';
}
}
<?php
// Format and print out the table.
return theme('table', array(
'header' => $table_header,
'rows' => $table_rows,
'id' => 'table-articles',
'class' => 'articles',
));
<?php
// Table header
$table_header = array(
// Column 1
'nid' => array(
'data' => 'Nid',
'class' => 'col-nid',
),
// Column 2
<?php
// Table rows
$rows = array(
// Row 1
array(
'data' => array(
// Column 1
'fruit' => array(
'data' => t('Apple'),
<?php
// Table header
$header = array(
// Column 1
'fruit' => array(
'data' => t('Fruit'),
'id' => 'head-fruit',
'class' => 'col-fruit',
),
<?php
// Table header
$header = array(
'fruit' => t('Fruit'),
'a' => t('Vitamin A'),
'b1' => t('Vitamin B1'),
'b2' => t('Vitamin B2'),
);