From ec78589174fef03608524d39e9ba35c5584efe39 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 30 Jan 2010 04:14:17 +0000 Subject: #537750 by yched: Added Field UI for comments. --- modules/comment/comment.module | 60 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'modules/comment/comment.module') diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 97d862f73..556c234c2 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -104,9 +104,6 @@ function comment_entity_info() { 'id' => 'cid', 'bundle' => 'node_type', ), - 'bundle keys' => array( - 'bundle' => 'type', - ), 'bundles' => array(), 'view modes' => array( 'full' => array( @@ -120,12 +117,36 @@ function comment_entity_info() { foreach (node_type_get_names() as $type => $name) { $return['comment']['bundles']['comment_node_' . $type] = array( 'label' => $name, + 'admin' => array( + // Place the Field UI paths for comments one level below the + // corresponding paths for nodes, so that they appear in the same set + // of local tasks. Note that the paths use a different placeholder name + // and thus a different menu loader callback, so that Field UI page + // callbacks get a comment bundle name from the node type in the URL. + // @see comment_node_type_load() + // @see comment_menu_alter() + 'path' => 'admin/structure/types/manage/%comment_node_type/comment', + 'bundle argument' => 4, + 'real path' => 'admin/structure/types/manage/' . str_replace('_', '-', $type) . '/comment', + 'access arguments' => array('administer content types'), + ), ); } return $return; } +/** + * Menu loader callback for Field UI paths. + * + * Return a comment bundle name from a node type in the URL. + */ +function comment_node_type_load($name) { + if ($type = node_type_get_type(strtr($name, array('-' => '_')))) { + return 'comment_node_' . $type->type; + } +} + /** * Entity path callback. */ @@ -133,6 +154,32 @@ function comment_path($comment) { return 'comment/' . $comment->cid; } +/** + * Implements hook_field_extra_fields(). + */ +function comment_field_extra_fields() { + $return = array(); + + foreach (node_type_get_types() as $type) { + if (variable_get('comment_subject_field_' . $type->type, 1) == 1) { + $return['comment']['comment_node_' . $type->type] = array( + 'author' => array( + 'label' => t('Author'), + 'description' => t('Author textfield'), + 'weight' => -2, + ), + 'title' => array( + 'label' => t('Subject'), + 'description' => t('Subject textfield'), + 'weight' => -1, + ), + ); + } + } + + return $return; +} + /** * Implements hook_theme(). */ @@ -2501,6 +2548,13 @@ function comment_ranking() { function comment_menu_alter(&$items) { // Add comments to the description for admin/content. $items['admin/content']['description'] = "Administer content and comments"; + + // Adjust the Field UI tabs on admin/structure/types/manage/[node-type]. + // @see comment_entity_info() + $items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields'; + $items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3; + $items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display'; + $items['admin/structure/types/manage/%comment_node_type/comment/display']['weight'] = 4; } /** -- cgit v1.2.3