| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_menu().
|
| 6 |
*/
|
| 7 |
function record_test_menu() {
|
| 8 |
$items['record/add'] = array(
|
| 9 |
'title' => 'Create record',
|
| 10 |
'page callback' => 'record_test_add_page',
|
| 11 |
'access arguments' => array('access content'),
|
| 12 |
);
|
| 13 |
|
| 14 |
$schema = drupal_get_schema();
|
| 15 |
foreach (array_keys($schema) as $type) {
|
| 16 |
$type_url_str = str_replace('_', '-', $type);
|
| 17 |
$items['record/add/'. $type_url_str] = array(
|
| 18 |
'title' => drupal_ucfirst($type),
|
| 19 |
'description' => $schema[$type]['description'],
|
| 20 |
'page callback' => 'record_test_add',
|
| 21 |
'page arguments' => array(2),
|
| 22 |
'access arguments' => array('access content'),
|
| 23 |
);
|
| 24 |
}
|
| 25 |
|
| 26 |
return $items;
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Implementation of hook_simpletest().
|
| 31 |
*/
|
| 32 |
function record_test_simpletest() {
|
| 33 |
$dir = drupal_get_path('module', 'record_test'). '/tests';
|
| 34 |
$tests = file_scan_directory($dir, '\.test$');
|
| 35 |
return array_keys($tests);
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_theme().
|
| 40 |
*/
|
| 41 |
function record_test_theme() {
|
| 42 |
return array(
|
| 43 |
'record_test_add_list' => array(
|
| 44 |
'arguments' => array('content' => NULL),
|
| 45 |
),
|
| 46 |
);
|
| 47 |
}
|
| 48 |
|
| 49 |
function record_test_add_page() {
|
| 50 |
$item = menu_get_item();
|
| 51 |
$content = system_admin_menu_block($item);
|
| 52 |
return theme('record_test_add_list', $content);
|
| 53 |
}
|
| 54 |
|
| 55 |
/**
|
| 56 |
* Theme record add list.
|
| 57 |
*
|
| 58 |
* @param $content
|
| 59 |
* An array describing a record type.
|
| 60 |
*/
|
| 61 |
function theme_record_test_add_list($content) {
|
| 62 |
$output = '';
|
| 63 |
|
| 64 |
if ($content) {
|
| 65 |
$output = '<dl class="node-type-list">';
|
| 66 |
foreach ($content as $item) {
|
| 67 |
$output .= '<dt>'. l($item['title'], $item['href'], $item['options']) .'</dt>';
|
| 68 |
$output .= '<dd>'. $item['description'] .'</dd>';
|
| 69 |
}
|
| 70 |
$output .= '</dl>';
|
| 71 |
}
|
| 72 |
return $output;
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Generate a form to add a record.
|
| 77 |
*
|
| 78 |
* @param $type
|
| 79 |
* A table name.
|
| 80 |
*/
|
| 81 |
function record_test_add($type) {
|
| 82 |
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
|
| 83 |
|
| 84 |
drupal_set_title(t('Create @name', array('@name' => $type)));
|
| 85 |
$output = drupal_get_form($type .'_record_form', $type);
|
| 86 |
|
| 87 |
return $output;
|
| 88 |
}
|