Snippets

Set taxonomy option by code

You'll need to create a custom module and use the hook_form_alter() function.

function example_form_alter(&$form, $form_state, $form_id) {
  $form['taxonomy'][2]['#default_value'] = array(0 => $term->tid);
}

Please note that the $form['taxonomy'][2]['#default_value'] is the vocabulary id.

Change select options within a nodereference

First you'll have to make use of hook_form_alter() function.

function example_form_alter(&$form, $form_state, $form_id) {
  $form['field_example_reference']['#pre_render'] = array('example_change_node_reference');
}

Now the node reference will look for a example_change_node_reference() function which will return an array of options.

function example_change_node_reference($element) {
      $element['nid']['nid']['#options'] = array($node->nid => $node->title);
  return $element;
 
}

Using hook_theme

Example of using hook_theme.

/**
 * Implementation of hook_theme().
 */
function example_theme() {
  return array(
    'example_taxonomy' => array(
      'template' => 'example-taxonomy',
      'arguments' => array('node' => NULL, 'options' => NULL),
    ),
    'example_taxonomy_terms' => array(
      'arguments' => array('voc' => NULL, 'node' => NULL, 'options' => NULL),
    ),
    'example_front_page' => array(
      'template' => 'example-front-page',
      'arguments' => array(),
    ),

Creating menus with hook_menu

Example of using hook_menu.

1. Create a empty page with no menu item.

function example_menu() {
  $items['page/page'] = array(
    'page callback' => 'example_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
    );
  return $items;
}
 
function example_page() {
  return 'example page';
}

2. Create admin page.

function example_menu() {
  $items['admin/settings/example'] = array(
    'title' => 'Example config',