? .svn ? 103834_nodeprofile_simpleblock.patch Index: nodeprofile.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.module,v retrieving revision 1.6 diff -u -p -r1.6 nodeprofile.module --- nodeprofile.module 9 Aug 2006 08:18:22 -0000 1.6 +++ nodeprofile.module 4 Jan 2007 13:41:46 -0000 @@ -99,3 +99,80 @@ function nodeprofile_node_settings_submi } } } + +/** + * @ingroup hook_block implementation + * implementation of hook_block + * @todo for nodefamily blocks: make sure we only load lonely nodes + */ +function nodeprofile_block($op = 'list', $delta = 0, $edit = array()){ + // The $op parameter determines what piece of information is being requested. + switch ($op) { + case 'list': + if (module_exist('nodefamily')) { // nodefamily specific blocks + foreach (nodefamily_get_parent_types() as $type) { + $blocks[$type]['info'] = t('My nodefamily for %type', array('%type' => node_get_name($type))); + } + } + return $blocks; + case 'view': default: + if (module_exist('nodefamily')) { // nodefamily specific blocks + $block['subject'] = t('My %type', array('%type' => node_get_name($delta))); + $block['content'] = nodeprofile_block_contents($delta); + return $block; + } + } +} + +/** + * @ingroup hook_block implementation + * Generate the content for the block + */ +function nodeprofile_block_contents($type) { + global $user; + $node = node_load(array('type' => $type, 'uid' => $user->uid)); + if ($children = nodefamily_relation_load($node)) { + foreach ($children as $profile) { + $types_met[] = $profile->type; + $items[] = theme('nodeprofile_block_item', $profile); + } + foreach (nodefamily_get_child_types($type) as $option) { + if (!in_array($option, $types_met)) { + $profile = new stdClass(); + $profile->type = $option; + $profile->title = node_get_name($option); + $items[] = theme('nodeprofile_block_item', $profile, array('create')); + } + } + return theme('item_list', $items); + } +} + +/** + * @ingroup themeable + * Generate an 'action'-link, like 'edit' or 'create' + */ +function theme_nodeprofile_block_item($profile, $actions = array('edit', 'delete')) { + $output = ''; + + if ($profile->nid) { + $output .= l($profile->title, 'node/'. $profile->nid); + } + else { + $output .= $profile->title; + } + + if (in_array('edit', $actions)) { + $output .= ' ['. l(t('edit'), 'node/'. $profile->nid .'/edit') .']'; + } + + if (in_array('create', $actions)) { + $output .= ' ['. l(t('create'), 'node/add/'. $profile->type) .']'; + } + + if (in_array('delete', $actions)) { + $output .= ' ['. l(t('delete'), 'node/'. $profile->nid .'/delete') .']'; + } + + return $output; +} \ No newline at end of file