diff --git a/modules/comment/comment.install b/modules/comment/comment.install index 0213808..d454b06 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -17,15 +17,15 @@ function comment_uninstall() { $node_types = array_keys(node_type_get_types()); foreach ($node_types as $node_type) { field_attach_delete_bundle('comment', 'comment_node_' . $node_type); - variable_del('comment_' . $node_type); - variable_del('comment_anonymous_' . $node_type); - variable_del('comment_controls_' . $node_type); - variable_del('comment_default_mode_' . $node_type); - variable_del('comment_default_order_' . $node_type); - variable_del('comment_default_per_page_' . $node_type); - variable_del('comment_form_location_' . $node_type); - variable_del('comment_preview_' . $node_type); - variable_del('comment_subject_field_' . $node_type); + variable_del('comment_node_' . $node_type); + variable_del('comment_anonymous_node_' . $node_type); + variable_del('comment_controls_node_' . $node_type); + variable_del('comment_default_mode_node_' . $node_type); + variable_del('comment_default_order_node_' . $node_type); + variable_del('comment_default_per_page_node_' . $node_type); + variable_del('comment_form_location_node_' . $node_type); + variable_del('comment_preview_node_' . $node_type); + variable_del('comment_subject_field_node_' . $node_type); } } @@ -259,3 +259,25 @@ function comment_schema() { return $schema; } + +/** + * + */ +function comment_update_8000() { + foreach (node_type_get_types() as $type) { + $old_keys[] = 'comment_'; + $old_keys[] = 'comment_default_mode_'; + $old_keys[] = 'comment_default_per_page_'; + $old_keys[] = 'comment_anonymous_'; + $old_keys[] = 'comment_subject_field_'; + $old_keys[] = 'comment_form_location_'; + $old_keys[] = 'comment_preview_'; + foreach ($old_keys as $old_key) { + $new_key = "{$old_key}_node_{$type}"; + $old_key = "{$old_key}_{$type}"; + $variable = variable_get($old_key); + variable_set($new_key, $variable); + variable_del($old_key); + } + } +} diff --git a/modules/comment/comment.module b/modules/comment/comment.module index ae9278c..5f2e52c 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -609,6 +609,12 @@ function theme_comment_block() { } /** + * @TODO: Implements hook_entity_view(). + */ +function comment_entity_view($entity, $entity_type, $view_mode, $langcode) { +} + +/** * Implements hook_node_view(). */ function comment_node_view($node, $view_mode) { @@ -1133,7 +1139,7 @@ function comment_form_node_type_form_alter(&$form, $form_state) { $form['comment']['comment'] = array( '#type' => 'select', '#title' => t('Default comment setting for new content'), - '#default_value' => variable_get('comment_' . $form['#node_type']->type, COMMENT_NODE_OPEN), + '#default_value' => variable_get('comment_node_' . $form['#node_type']->type, COMMENT_NODE_OPEN), '#options' => array( COMMENT_NODE_OPEN => t('Open'), COMMENT_NODE_CLOSED => t('Closed'), @@ -1143,19 +1149,19 @@ function comment_form_node_type_form_alter(&$form, $form_state) { $form['comment']['comment_default_mode'] = array( '#type' => 'checkbox', '#title' => t('Threading'), - '#default_value' => variable_get('comment_default_mode_' . $form['#node_type']->type, COMMENT_MODE_THREADED), + '#default_value' => variable_get('comment_default_mode_node_' . $form['#node_type']->type, COMMENT_MODE_THREADED), '#description' => t('Show comment replies in a threaded list.'), ); $form['comment']['comment_default_per_page'] = array( '#type' => 'select', '#title' => t('Comments per page'), - '#default_value' => variable_get('comment_default_per_page_' . $form['#node_type']->type, 50), + '#default_value' => variable_get('comment_default_per_page_node_' . $form['#node_type']->type, 50), '#options' => _comment_per_page(), ); $form['comment']['comment_anonymous'] = array( '#type' => 'select', '#title' => t('Anonymous commenting'), - '#default_value' => variable_get('comment_anonymous_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT), + '#default_value' => variable_get('comment_anonymous_node_' . $form['#node_type']->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT), '#options' => array( COMMENT_ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'), COMMENT_ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'), @@ -1166,17 +1172,17 @@ function comment_form_node_type_form_alter(&$form, $form_state) { $form['comment']['comment_subject_field'] = array( '#type' => 'checkbox', '#title' => t('Allow comment title'), - '#default_value' => variable_get('comment_subject_field_' . $form['#node_type']->type, 1), + '#default_value' => variable_get('comment_subject_field_node_' . $form['#node_type']->type, 1), ); $form['comment']['comment_form_location'] = array( '#type' => 'checkbox', '#title' => t('Show reply form on the same page as comments'), - '#default_value' => variable_get('comment_form_location_' . $form['#node_type']->type, COMMENT_FORM_BELOW), + '#default_value' => variable_get('comment_form_location_node_' . $form['#node_type']->type, COMMENT_FORM_BELOW), ); $form['comment']['comment_preview'] = array( '#type' => 'radios', '#title' => t('Preview comment'), - '#default_value' => variable_get('comment_preview_' . $form['#node_type']->type, DRUPAL_OPTIONAL), + '#default_value' => variable_get('comment_preview_node_' . $form['#node_type']->type, DRUPAL_OPTIONAL), '#options' => array( DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), @@ -1239,6 +1245,20 @@ function comment_form_node_form_alter(&$form, $form_state) { } /** + * Implements hook_entity_load(). + */ +function comment_entity_load($entities, $type) { + $comments_enabled = array(); + + $entity_info = entity_get_info($type); + # dsm($entity_info); + + foreach ($entities as $entity) { + # dsm($entity); + } +} + +/** * Implements hook_node_load(). */ function comment_node_load($nodes, $types) { @@ -2717,3 +2737,32 @@ function comment_file_download_access($field, $entity_type, $entity) { return FALSE; } } + +/** + * Implements hook_schema_alter(). + * Create comment field to entity base and revision tables. + */ +function comment_schema_alter(&$schema) { + foreach (entity_get_info() as $entity_type => $entity_info) { + if (!empty($entity_info['comment'])) { + foreach (array('base table', 'revision table') as $i) { + if (isset($entity_info[$i])) { + $table_name = $entity_info[$i]; + if (isset($schema[$table_name]) && !isset($schema[$table_name]['fields']['comment'])) { + $schema[$table_name]['fields']['comment'] = array( + 'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ); + + try { + db_add_field($table_name, 'comment', $schema[$table_name]['fields']['comment']); + } + catch (Exception $e) {} + } + } + } + } + } +} diff --git a/modules/node/node.install b/modules/node/node.install index 3f732a4..48cf50a 100644 --- a/modules/node/node.install +++ b/modules/node/node.install @@ -70,12 +70,6 @@ function node_schema() { 'not null' => TRUE, 'default' => 0, ), - 'comment' => array( - 'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), 'promote' => array( 'description' => 'Boolean indicating whether the node should be displayed on the front page.', 'type' => 'int', @@ -234,12 +228,6 @@ function node_schema() { 'not null' => TRUE, 'default' => 1, ), - 'comment' => array( - 'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).', - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), 'promote' => array( 'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.', 'type' => 'int', diff --git a/modules/node/node.module b/modules/node/node.module index 0c3cfb7..45b5ce0 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -172,6 +172,7 @@ function node_entity_info() { 'revision table' => 'node_revision', 'uri callback' => 'node_uri', 'fieldable' => TRUE, + 'comment' => TRUE, 'entity keys' => array( 'id' => 'nid', 'revision' => 'vid',