diff --git a/nodefamily.module b/nodefamily.module index c73fd83..8cfd527 100644 --- a/nodefamily.module +++ b/nodefamily.module @@ -6,24 +6,6 @@ * Builds node families based on content types and author information */ - -/** - * Implementation of hook_menu(). - */ -function nodefamily_menu($may_cache) { - $items = array(); - - if ($may_cache) { - $items[] = array( - 'path' => 'nodefamily', - 'callback' => 'nodefamily_lonely_node_page_args', - 'access' => user_access('access content'), - 'type' => MENU_CALLBACK, - ); - } - return $items; -} - /** * Determine if adding the relation between parent and child would * result in a cycle. @@ -655,155 +637,6 @@ function nodefamily_relation_load_siblings(&$node, $status = 1, $rel_name = 'nod */ - -/** - * Provide a unique URL for adding/editing nodes of types - * with a maximum population of one. - */ -function nodefamily_lonely_node_page_args() { - - $types = node_get_types(); - $typename = arg(1); - - if (!$types[$typename] || nodefamily_content_type_get_max($typename) != 1) { - drupal_not_found(); - exit; - } - - $uid = (arg(2) && is_numeric(arg(2))) ? arg(2) : NULL; - - return nodefamily_lonely_node_page($typename, $uid); -} - - -function nodefamily_lonely_node_page($typename, $uid = NULL) { - global $user; - - $node = node_load(array('type' => $typename, 'uid' => $uid ? $uid : $user->uid)); - - if (!$node) { - // show add form - return node_add($typename); - } - else if (node_access('update', $node)) { - //show edit form - return node_page_edit($node); - } - drupal_not_found(); -} - - - -/** - * Pageroute integration - */ - -/** - * Implementation of hook_pageroute_info(). - */ -function nodefamily_pageroute_info() { - return array( - 'manage_lonely' => array('name' => t('Lonely node management'), 'base' => 'nodefamily', 'default_target' => PAGEROUTE_FORWARD), - 'view_lonely' => array('name' => t('Lonely node display'), 'base' => 'nodefamily'), - ); -} - -/* - * Implementation of pageroutes' hook_page() - */ -function nodefamily_page_manage_lonely($route, $page, $form) { - $task = pageroute_page_arg($page, 0); - if ($task == 'delete') { - $page->arg_offset++; //the delete subpage is to be shown.. - } - $node = node_load(array( - 'type' => $page->options['content-type'], - 'uid' => $uid = pageroute_page_get_uid($page), - )); - //do we need to show the delete confirm form? - if ($task == 'delete') { - return pageroute_node_delete_confirm($node, $page); - } - //the node edit form page type will present an add form for us, if there is no node id - return pageroute_page_edit($route, $page, $form, $node->nid ? $node->nid : FALSE); -} - -/* - * Implementation of pageroutes' hook_page() - */ -function nodefamily_page_view_lonely($route, $page, $form) { - $node = node_load(array( - 'type' => $page->options['content-type'], - 'uid' => pageroute_page_get_uid($page), - )); - if ($node->nid && node_access('view', $node)) { - $page->options['nid'] = $node->nid; - return pageroute_page_view($route, $page, $form); - } - else { - $form['empty'] = array('#value' => theme('nodefamily_lonely_node_view_empty')); - return $form; - } -} - -function theme_nodefamily_lonely_node_view_empty() { - return '
'. - t('There is no node of this type.') .'
'; -} - -/* - * Implementations of hook_page_ui(). - */ -function nodefamily_page_view_lonely_ui($route, $page, &$form, $type) { - $form['options']['content-type'] = array( - '#type' => 'select', - '#title' => t('content type'), - '#options' => nodefamily_lonely_node_types(), - '#required' => TRUE, - '#default_value' => $page->options['content-type'], - '#weight' => 2, - '#description' => t('You can only use content types with a maximum '. - 'nodefamily population set to one!'), - ); -} -function nodefamily_page_manage_lonely_ui($route, $page, &$form, $type) { - nodefamily_page_view_lonely_ui($route, $page, &$form, $type); - pageroute_pages_node_ui($route, $page, &$form, $type); -} - -/* - * Returns an array of lonely node types - */ -function nodefamily_lonely_node_types($op = 'names') { - $types = node_get_types($op); - $lonely_node_types = array(); - foreach($types as $typename => $type) { - if (nodefamily_content_type_get_max($typename) == 1) { - $lonely_node_types[$typename] = $type; - } - } - return $lonely_node_types; -} - -/* - * Implementations of hook_page_help(). - */ -function nodefamily_page_manage_lonely_help() { - return t('The "lonely" page types may be used only with content types, '. - 'which are restricted to a maximum population of one by the '. - 'nodefamily module. Then you can use the lonely node '. - 'management page to add/edit the "lonely node" as it might be '. - 'useful e.g. for user profiles.'); -} -function nodefamily_page_view_lonely_help() { - return t('The lonely node display page can be used to view this lonely '. - 'node. This might be useful for displaying the lonely node after'. - 'creation or update. However keep in mind that there will be '. - 'a (themeable) "There is no node of this type." message if there is no '. - 'node that can be displayed.'); -} - - /** * Views integration */