$type) { if ($section == 'node/add#content-' . $type_name) { return t($types[$type_name]->description); } if ($section == 'node/add/content-' . $type) { return t($types[$type_name]->help); } } } } /** * Implementation of hook_perm(). */ function simplenode_perm() { $perms = array('administer content types'); foreach (_simplenode_types() as $name => $type) { $perms[] = 'create '. $name .' content'; $perms[] = 'edit own '. $name .' content'; } return $perms; } /** * Implementation of hook_menu(). */ function simplenode_menu($may_cache) { $items = array(); $access = user_access('administer content types'); if ($may_cache) { $items[] = array('path' => 'admin/node/types', 'title' => t('content types'), 'callback' => '_simplenode_admin_types_overview', 'access' => $access); $types = _simplenode_types(); foreach ($types as $type_name => $type) { $items[] = array('path' => 'node/add/content-'. $type_name, 'title' => t($type->label), 'access' => user_access('create '. $type_name .' content')); } } else { if (arg(0) == 'admin' && arg(1) == 'node' && arg(2) == 'types' && arg(3)) { $types = _simplenode_types(); if (isset($types[arg(3)])) { $items[] = array('path' => 'admin/node/types/'. arg(3), 'title' => t($types[arg(3)]->label), 'callback' => '_simplenode_admin_type', 'access' => $access, 'callback arguments' => array(arg(3)), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/node/types/'. arg(3) .'/delete', 'title' => t('delete'), 'callback' => '_simplenode_admin_type_deleteform', 'access' => $access, 'callback arguments' => arg(3), 'type' => MENU_CALLBACK, 'weight' => -10); } } } return $items; } /** * Implementation of hook_node_types(). */ function simplenode_node_types() { $types = array(); foreach (_simplenode_types() as $name => $type) { $types[] = 'content-' . $name; } return $types; } /** * Implementation of hook_node_name(). */ function simplenode_node_name($node) { $types = _simplenode_types(); $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); return t($types[substr($type, 8)]->label); } /** * Implementation of hook_access(). */ function simplenode_access($op, $node) { global $user; $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); $type = substr($type, 8); if ($op == 'create') { return user_access('create '. $type .' content'); } if ($op == 'update' || $op == 'delete') { if (user_access('edit own '. $type .' content') && ($user->uid == $node->uid)) { return TRUE; } } } /** * Menu callback; presents a listing of content types. */ function _simplenode_admin_types_overview() { $op = $_POST['op']; $edit = $_POST['edit']; switch ($op) { case t('Add content type'): _simplenode_admin_type_add($edit['type_name'], $edit['label'], $edit['description'], $edit['help']); break; } $types = _simplenode_types(); $header = array(t('Label'), t('Name'), t('Description'), array('data' => t('Operations'), 'colspan' => 2)); $rows = array(); foreach ($types as $type) { $row = array(); $row[] = $type->label; $row[] = $type->type_name; $row[] = $type->description; $row[] = l(t('edit'), 'admin/node/types/'. $type->type_name); $row[] = l(t('delete'), 'admin/node/types/'. $type->type_name .'/delete'); $rows[] = $row; } $group = theme('table', $header, $rows); $output = '
To add a new content type, type its name here. After it has been added, you can edit it.
'); // TODO: we are currently limited to 24 chars for the content type name // because the node table's type field is limited to 32 chars // and we use 8 of those for 'content-', e.g. 'content-foo' $form = form_textfield(t('Label'), 'label', '', 40, 255, t('Friendly name of your content type.'), NULL, TRUE); $form .= form_textfield(t('Name'), 'type_name', '', 40, 23, t('Short name, used in urls. No spaces or weird characters.'), NULL, TRUE); $form .= form_textfield(t('Description'), 'description', '', 80, 255); $form .= form_textarea(t('Help text'), 'help', $type->help, 60, 5, t('Instructions to present to the user when adding new content of this type.')); $form .= form_submit(t('Add content type')); $group .= form($form); $output .= '