diff --git a/core/modules/comment/comment.field.inc b/core/modules/comment/comment.field.inc index 9e7b7dd..cc1e3d2 100644 --- a/core/modules/comment/comment.field.inc +++ b/core/modules/comment/comment.field.inc @@ -56,17 +56,24 @@ function comment_field_instance_settings_form($field, $instance) { 'library' => array(array('comment', 'drupal.comment')), ), ); + // Preserve this settings for BC. @see comment_field_info $form['comment']['comment_default_mode'] = array( - '#type' => 'checkbox', - '#title' => t('Threading'), - '#default_value' => $settings['comment_default_mode'], - '#description' => t('Show comment replies in a threaded list.'), + '#type' => 'value', + '#value' => $settings['comment_default_mode'], ); $form['comment']['comment_default_per_page'] = array( - '#type' => 'select', - '#title' => t('Comments per page'), - '#default_value' => $settings['comment_default_per_page'], - '#options' => _comment_per_page(), + '#type' => 'value', + '#value' => $settings['comment_default_per_page'], + ); + $form['comment']['comment_form_location'] = array( + '#type' => 'value', + '#value' => $settings['comment_form_location'], + ); + // Comment form settings. + $form['comment']['comment_subject_field'] = array( + '#type' => 'checkbox', + '#title' => t('Allow comment title'), + '#default_value' => $settings['comment_subject_field'], ); $form['comment']['comment_anonymous'] = array( '#type' => 'select', @@ -79,16 +86,6 @@ function comment_field_instance_settings_form($field, $instance) { ), '#access' => user_access('post comments', drupal_anonymous_user()), ); - $form['comment']['comment_subject_field'] = array( - '#type' => 'checkbox', - '#title' => t('Allow comment title'), - '#default_value' => $settings['comment_subject_field'], - ); - $form['comment']['comment_form_location'] = array( - '#type' => 'checkbox', - '#title' => t('Show reply form on the same page as comments'), - '#default_value' => $settings['comment_form_location'], - ); $form['comment']['comment_preview'] = array( '#type' => 'radios', '#title' => t('Preview comment'), diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 426f093..1418851 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -615,10 +615,15 @@ function comment_update_8006(&$sandbox) { _update_7000_field_create_instance($field, $instance); // Prepare defaults for the default and full view modes. + $formatter_settings = array( + 'default_mode' => $instance_settings['comment_default_mode'], + 'per_page' => $instance_settings['comment_default_per_page'], + 'form_location' => $instance_settings['comment_form_location'], + ); $display_options_default = array( 'label' => 'hidden', 'type' => 'comment_default', - 'settings' => array(), + 'settings' => $formatter_settings, 'weight' => 1, ); @@ -635,6 +640,17 @@ function comment_update_8006(&$sandbox) { ->save(); update_config_manifest_add('entity.display', array($display->get('id'))); + // Update teaser display with links formatter. + $display_options = array( + 'label' => 'hidden', + 'type' => 'comment_links', + 'settings' => array('comment' => 1, 'new' => 1, 'add' => 1), + ); + $display = _update_8000_entity_get_display('node', $node_type, 'teaser'); + $display->set('content.' . $field['field_name'], $display_options) + ->save(); + update_config_manifest_add('entity.display', array($display->get('id'))); + // Clean up old variables. variable_del('comment_' . $node_type); variable_del('comment_default_mode_' . $node_type); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index a7b45a3..1574c9e 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -124,128 +124,6 @@ function comment_help($path, $arg) { } /** - * Implements hook_entity_view(). - * - * @todo Make node links as comment_links formatter http://drupal.org/node/1901110 - */ -function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $view_mode, $langcode) { - if ($entity->entityType() != 'node') { - // Only content needs comment links. - return; - } - $fields = field_info_instances($entity->entityType(), $entity->bundle()); - foreach ($fields as $field_name => $instance) { - $links = array(); - $field = field_info_field($field_name); - if ($field['type'] != 'comment') { - continue; - } - $values = field_get_items($entity, $field_name); - // @todo Field instance should provide always default value http://drupal.org/node/1919834 - $commenting_status = isset($values[0]['status']) ? $values[0]['status'] : NULL; - if (isset($commenting_status) && $commenting_status) { - // Entity have comment open or close. - $uri = $entity->uri(); - if ($view_mode == 'rss') { - // Add a comments RSS element which is a URL to the comments of this node. - if (!empty($uri['options'])) { - $uri['options']['fragment'] = 'comments'; - $uri['options']['absolute'] = TRUE; - } - $entity->rss_elements[] = array( - 'key' => 'comments', - 'value' => url($uri['path'], $uri['options']) - ); - } - elseif ($view_mode == 'teaser') { - // Teaser view: display the number of comments that have been posted, - // or a link to add new comments if the user has permission, the node - // is open to new comments, and there currently are none. - if (user_access('access comments')) { - if (!empty($entity->comment_statistics[$field_name]->comment_count)) { - $links['comment-comments'] = array( - 'title' => format_plural($entity->comment_statistics[$field_name]->comment_count, '1 comment', '@count comments'), - 'href' => $uri['path'], - 'attributes' => array('title' => t('Jump to the first comment of this posting.')), - 'fragment' => 'comments', - 'html' => TRUE, - ); - // Show a link to the first new comment. - if ($new = comment_num_new($entity->id(), $entity->entityType(), $field_name)) { - $links['comment-new-comments'] = array( - 'title' => format_plural($new, '1 new comment', '@count new comments'), - 'href' => $uri['path'], - 'query' => comment_new_page_count($entity->comment_statistics[$field_name]->comment_count, $new, $entity, $field_name), - 'attributes' => array('title' => t('Jump to the first new comment of this posting.')), - 'fragment' => 'new', - 'html' => TRUE, - ); - } - } - } - // Provide a link to new comment form. - if ($commenting_status == COMMENT_OPEN) { - $comment_form_location = $instance['settings']['comment']['comment_form_location']; - if (user_access('post comments')) { - $links['comment-add'] = array( - 'title' => t('Add new comment'), - 'href' => $uri['path'], - 'attributes' => array('title' => t('Add a new comment to this page.')), - 'fragment' => 'comment-form', - ); - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) { - $links['comment-add']['href'] = 'comment/reply/'. $entity->entityType() . '/' . $entity->id() .'/' . $field_name; - } - } - else { - $links['comment-forbidden'] = array( - 'title' => theme('comment_post_forbidden', array('entity' => $entity, 'field_name' => $field_name)), - 'html' => TRUE, - ); - } - } - } - elseif ($view_mode != 'search_index' && $view_mode != 'search_result') { - // Entity in other view modes: add a "post comment" link if the user is - // allowed to post comments and if this entity is allowing new comments. - // But we don't want this link if we're building the entity for search - // indexing or constructing a search result excerpt. - if ($commenting_status == COMMENT_OPEN) { - $comment_form_location = $instance['settings']['comment']['comment_form_location']; - if (user_access('post comments')) { - // Show the "post comment" link if the form is on another page, or - // if there are existing comments that the link will skip past. - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE || (!empty($entity->comment_statistics[$field_name]->comment_count) && user_access('access comments'))) { - $links['comment-add'] = array( - 'title' => t('Add new comment'), - 'attributes' => array('title' => t('Share your thoughts and opinions related to this item.')), - 'href' => $uri['path'], - 'fragment' => 'comment-form', - ); - if ($comment_form_location == COMMENT_FORM_SEPARATE_PAGE) { - $links['comment-add']['href'] = 'comment/reply/'. $entity->entityType() . '/' . $entity->id() .'/' . $field_name; - } - } - } - else { - $links['comment-forbidden'] = array( - 'title' => theme('comment_post_forbidden', array('entity' => $entity, 'field_name' => $field_name)), - 'html' => TRUE, - ); - } - } - } - } - - $entity->content['links']['comment__' . $field_name] = array( - '#theme' => 'links__entity__comment__' . $field_name, - '#links' => $links, - '#attributes' => array('class' => array('links', 'inline')), - ); - } -} - -/** * Implements hook_entity_view_mode_info(). */ function comment_entity_view_mode_info() { @@ -664,9 +542,10 @@ function comment_get_recent($number = 10) { * "page=X" if the page number is greater than zero; empty string otherwise. */ function comment_new_page_count($num_comments, $new_replies, EntityInterface $entity, $field_name = 'comment') { - $instance = field_info_instance($entity->entityType(), $field_name, $entity->bundle()); - $mode = $instance['settings']['comment']['comment_default_mode']; - $comments_per_page = $instance['settings']['comment']['comment_default_per_page']; + // Get default settings from default view mode. + $component = entity_get_display($entity->entityType(), $entity->bundle(), 'default')->getComponent($field_name); + $mode = $component['settings']['default_mode']; + $comments_per_page = $component['settings']['per_page']; $pagenum = NULL; $flat = $mode == COMMENT_MODE_FLAT ? TRUE : FALSE; if ($num_comments <= $comments_per_page) { @@ -892,8 +771,10 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen * * @param array $comments * An array of comment objects, keyed by comment ID. + * @param int $mode + * The comment display mode; COMMENT_MODE_FLAT or COMMENT_MODE_THREADED. */ -function comment_prepare_thread(&$comments) { +function comment_prepare_thread(&$comments, $mode) { // A flag stating if we are still searching for first new comment on the thread. $first_new = TRUE; @@ -908,6 +789,10 @@ function comment_prepare_thread(&$comments) { $comment->first_new = TRUE; } + // Do not apply treading for flat mode. + if ($mode == COMMENT_MODE_FLAT) { + continue; + } // The $divs element instructs #prefix whether to add an indent div or // close existing divs (a negative value). $comment->depth = count(explode('.', $comment->thread->value)) - 1; @@ -1210,15 +1095,16 @@ function comment_node_update_index(Node $node, $langcode) { if ($index_comments) { foreach (comment_get_comment_fields('node') as $field_name => $info) { - $instance = field_info_instance('node', $field_name, $node->type); - $mode = $instance['settings']['comment']['comment_default_mode']; - $comments_per_page = $instance['settings']['comment']['comment_default_per_page']; + // Get default settings from default view mode. + $component = entity_get_display('node', $node->type, 'default')->getComponent($field_name); + $mode = $component['settings']['default_mode']; + $comments_per_page = $component['settings']['per_page']; if (($items = field_get_items($node, $field_name)) && // @todo Field instance should provide always default value http://drupal.org/node/1919834 isset($items[0]['status']) && $items[0]['status'] && $cids = comment_get_thread($node, $field_name, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); - comment_prepare_thread($comments); + comment_prepare_thread($comments, $mode); $build = comment_view_multiple($comments); $return .= drupal_render($build); } @@ -1512,6 +1398,7 @@ function comment_get_display_ordinal($cid, $instance) { */ function comment_get_display_page($cid, $instance) { $ordinal = comment_get_display_ordinal($cid, $instance); + // @todo Get settings from default display. $comments_per_page = $instance['settings']['comment']['comment_default_per_page']; return floor($ordinal / $comments_per_page); } @@ -1584,7 +1471,7 @@ function comment_preview(Comment $comment) { } $preview_build['comment_output_below'] = $build; - $preview_build['comment_output_below']['#weight'] = 100; + $preview_build['comment_output_below']['#weight'] = 1000; return $preview_build; } @@ -1810,7 +1697,7 @@ function _comment_get_modes() { * Returns an array of "comments per page" values that users can select from. */ function _comment_per_page() { - return drupal_map_assoc(array(10, 30, 50, 70, 90, 150, 200, 250, 300)); + return drupal_map_assoc(array(1, 10, 30, 50, 70, 90, 150, 200, 250, 300)); } /** @@ -2223,6 +2110,17 @@ function comment_field_create_instance($instance) { if ($field['type'] == 'comment') { _comment_body_field_create($instance['entity_type'], $instance['bundle'], $instance['field_name']); cache()->delete('comment_entity_info'); + // Add BC for node teaser. + if ($instance['entity_type'] == 'node' && $teaser_display = entity_load('entity_display', $instance['entity_type'] . '.' . $instance['bundle'] . '.teaser')) { + // $bundle_settings = field_bundle_settings($this->entity_type, $this->bundle); + $teaser_display + ->setComponent($instance['field_name'], array( + 'label' => 'hidden', + 'type' => 'comment_links', + 'weight' => 10, + )) + ->save(); + } } } diff --git a/core/modules/comment/comment.pages.inc b/core/modules/comment/comment.pages.inc index 943b87a..308105c 100644 --- a/core/modules/comment/comment.pages.inc +++ b/core/modules/comment/comment.pages.inc @@ -39,6 +39,7 @@ */ function comment_reply(EntityInterface $entity, $field_name, $pid = NULL) { // Set the breadcrumb trail. + // @todo - test behaviour when entities don't have uris. $uri = $entity->uri(); drupal_set_breadcrumb(array( l(t('Home'), NULL), diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index e255eb0..ff996ba 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\comment\CommentFormController. + * Contains \Drupal\comment\CommentFormController. */ namespace Drupal\comment; @@ -17,7 +17,7 @@ class CommentFormController extends EntityFormControllerNG { /** - * Overrides \Drupal\Core\Entity\EntityFormControllerNG::form(). + * Overrides EntityFormControllerNG::form(). */ public function form(array $form, array &$form_state, EntityInterface $comment) { global $user; diff --git a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php index 2707c1a..969e0b6 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentRenderController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentRenderController.php @@ -82,10 +82,7 @@ protected function alterBuild(array &$build, EntityInterface $comment, EntityDis parent::alterBuild($build, $comment, $display, $view_mode, $langcode); if (empty($comment->in_preview)) { $prefix = ''; - $comment_entity = entity_load($comment->entity_type->value, $comment->entity_id->target_id); - $instance = field_info_instance($comment_entity->entityType(), $comment->field_name->value, $comment_entity->bundle()); - $is_threaded = isset($comment->divs) - && $instance['settings']['comment']['comment_default_mode'] == COMMENT_MODE_THREADED; + $is_threaded = isset($comment->divs); // Add 'new' anchor if needed. if (!empty($comment->first_new)) { diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 39d95ee..d960b75 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -364,7 +364,7 @@ public function baseFieldDefinitions() { 'description' => t("The comment 'new' marker for the current user (0 read, 1 new, 2 updated)."), 'type' => 'integer_field', 'computed' => TRUE, - 'class' => '\Drupal\comment\FieldNewItem', + 'class' => '\Drupal\comment\Type\CommentNewItem', ); return $properties; } diff --git a/core/modules/comment/lib/Drupal/comment/FieldNewItem.php b/core/modules/comment/lib/Drupal/comment/FieldNewItem.php deleted file mode 100644 index 7ef4092..0000000 --- a/core/modules/comment/lib/Drupal/comment/FieldNewItem.php +++ /dev/null @@ -1,40 +0,0 @@ - 'integer', - 'label' => t('Integer value'), - 'class' => '\Drupal\comment\FieldNewValue', - ); - } - return static::$propertyDefinitions; - } -} diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php index 0bbd2e3..91bd761 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentDefaultFormatter.php @@ -21,12 +21,62 @@ * label = @Translation("Comment List"), * field_types = { * "comment" + * }, + * settings = { + * "default_mode" = "COMMENT_MODE_THREADED", + * "per_page" = "50", + * "form_location" = "COMMENT_FORM_BELOW" * } * ) */ class CommentDefaultFormatter extends FormatterBase { /** + * Overrides FormatterBase::settingsForm(). + */ + public function settingsForm(array $form, array &$form_state) { + $settings = $this->settings; + $elements['default_mode'] = array( + '#type' => 'checkbox', + '#title' => t('Threading'), + '#default_value' => $settings['default_mode'], + '#description' => t('Show comment replies in a threaded list.'), + ); + $elements['per_page'] = array( + '#type' => 'select', + '#title' => t('Comments per page'), + '#default_value' => $settings['per_page'], + '#options' => _comment_per_page(), + ); + $elements['form_location'] = array( + '#type' => 'checkbox', + '#title' => t('Show reply form on the same page as comments'), + '#default_value' => $settings['form_location'], + ); + + return $elements; + } + + /** + * Overrides FormatterBase::settingsSummary(). + */ + public function settingsSummary() { + $summary = array(); + + if ($this->getSetting('default_mode')) { + $summary[] = t('Threading'); + } + if ($this->getSetting('per_page')) { + $summary[] = format_plural($this->getSetting('per_page'), '1 Comment per page', '@count Comments per page'); + } + if ($this->getSetting('form_location')) { + $summary[] = t('Show reply form'); + } + + return implode('
', $summary); + } + + /** * Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements(). */ public function viewElements(EntityInterface $entity, $langcode, array $items) { @@ -37,23 +87,16 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { // @todo Field instance should provide always default value http://drupal.org/node/1919834 $commenting_status = isset($items[0]['status']) ? $items[0]['status'] : COMMENT_OPEN; if ($commenting_status != COMMENT_HIDDEN && empty($entity->in_preview)) { - $comment_settings = $this->instance['settings']['comment']; + $comment_settings = $this->settings; // Only attempt to render comments if the entity has visible comments. // Unpublished comments are not included in // $entity->comment_statistics[$field_name]->comment_count, so show // comments unconditionally if the user is an administrator. - if (((!empty($entity->comment_statistics[$field['field_name']]->comment_count) && user_access('access comments')) || user_access('administer comments')) && - !empty($entity->content['#view_mode']) && - !in_array($entity->content['#view_mode'], array('search_result', 'search_index'))) { - - // Comment threads aren't added to search results/indexes using the - // formatter, @see comment_node_update_index(). - $mode = $comment_settings['comment_default_mode']; - $comments_per_page = $comment_settings['comment_default_per_page']; - if ($cids = comment_get_thread($entity, $field['field_name'], $mode, $comments_per_page)) { + if (((!empty($entity->comment_statistics[$field['field_name']]->comment_count) && user_access('access comments')) || user_access('administer comments'))) { + if ($cids = comment_get_thread($entity, $field['field_name'], $comment_settings['default_mode'], $comment_settings['per_page'])) { $comments = comment_load_multiple($cids); - comment_prepare_thread($comments); + comment_prepare_thread($comments, $comment_settings['default_mode']); $build = comment_view_multiple($comments); $build['pager']['#theme'] = 'pager'; $additions['comments'] = $build; @@ -61,11 +104,9 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { } // Append comment form if needed. - if ($commenting_status == COMMENT_OPEN && $comment_settings['comment_form_location'] == COMMENT_FORM_BELOW) { - // Only show the add comment form if the user has permission and the - // view mode is not search_result or search_index. - if (user_access('post comments') && !empty($entity->content['#view_mode']) && - !in_array($entity->content['#view_mode'], array('search_result', 'search_index'))) { + if ($commenting_status == COMMENT_OPEN && $comment_settings['form_location'] == COMMENT_FORM_BELOW) { + // Only show the add comment form if the user has permission. + if (user_access('post comments')) { $additions['comment_form'] = comment_add($entity, $field['field_name']); } } @@ -75,7 +116,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements[] = $additions + array( '#theme' => 'comment_wrapper__' . $entity->entityType() . '__' . $entity->bundle() . '__' . $field['field_name'], '#entity' => $entity, - '#display_mode' => $this->instance['settings']['comment']['comment_default_mode'], + '#display_mode' => $comment_settings['default_mode'], 'comments' => array(), 'comment_form' => array(), ); diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentLinksFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentLinksFormatter.php new file mode 100644 index 0000000..d49f7c7 --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Plugin/field/formatter/CommentLinksFormatter.php @@ -0,0 +1,155 @@ +settings; + $elements['comment'] = array( + '#type' => 'checkbox', + '#title' => t('Allow comments link'), + '#default_value' => !empty($settings['comment']), + ); + $elements['new'] = array( + '#type' => 'checkbox', + '#title' => t('Link to the first new comment of this posting.'), + '#default_value' => !empty($settings['new']), + ); + $elements['add'] = array( + '#type' => 'checkbox', + '#title' => t('Add a new comment link.'), + '#default_value' => !empty($settings['add']), + ); + + return $elements; + } + + /** + * Overrides FormatterBase::settingsSummary(). + */ + public function settingsSummary() { + $summary = array(); + + if ($this->getSetting('comment')) { + $summary[] = t('Comments'); + } + if ($this->getSetting('new')) { + $summary[] = t('New'); + } + if ($this->getSetting('add')) { + $summary[] = t('Add'); + } + if (empty($summary)) { + return t('No links displayed'); + } + else { + return t('Links: @links', array('@links' => implode(', ', $summary))); + } + } + + /** + * Implements FormatterInterface::viewElements(). + */ + public function viewElements(EntityInterface $entity, $langcode, array $items) { + $settings = $this->settings; + $field_name = $this->field['field_name']; + + // We only ever process first value. + // @todo Alter default field settings to + // disallow select more then 1 value cardinality. + $status = isset($items[0]['comment']) ? $items[0]['comment'] : COMMENT_OPEN;; + + $links = array(); + $uri = $entity->uri(); + foreach ($settings as $link => $v) { + + $link_attributes = array(); + switch ($link) { + case 'comment': + if (!empty($entity->comment_statistics[$field_name]->comment_count)) { + $link_attributes['title'] = format_plural($entity->comment_statistics[$field_name]->comment_count, '1 comment', '@count comments'); + $link_attributes['attributes'] = array('title' => t('Jump to the first comment of this posting.')); + $link_attributes['fragment'] = 'comments'; + $link_attributes['href'] = $uri['path']; + $link_attributes['options'] = $uri['options']; + } + break; + + case 'new': + if (!empty($entity->comment_statistics[$field_name]->comment_count) && $new = comment_num_new($entity->id(), $entity->entityType(), $field_name)) { + $link_attributes['title'] = format_plural($new, '1 new comment', '@count new comments'); + $link_attributes['attributes'] = array('title' => t('Jump to the first new comment of this posting.')); + $link_attributes['query'] = comment_new_page_count($entity->comment_statistics[$field_name]->comment_count, $new, $entity, $field_name); + $link_attributes['fragment'] = 'new'; + $link_attributes['href'] = $uri['path']; + $link_attributes['options'] = $uri['options']; + } + break; + + case 'add': + if ($status == COMMENT_OPEN) { + if (user_access('post comments')) { + $link_attributes['title'] = t('Add new comment'); + $link_attributes['attributes'] = array('title' => t('Add a new comment to this page.')); + $link_attributes['fragment'] = 'comment-form'; + $link_attributes['href'] = $uri['path']; + $link_attributes['options'] = $uri['options']; + if ($this->instance['settings']['comment']['comment_form_location'] == COMMENT_FORM_SEPARATE_PAGE) { + $link_attributes['href'] = 'comment/reply/'. $entity->entityType() . '/' . $entity->id() .'/' . $field_name; + } + } + else { + $link = 'forbidden'; + $link_attributes['title'] = theme('comment_post_forbidden', array('entity' => $entity, 'field_name' => $field_name)); + } + } + break; + } + if ($link_attributes) { + // Set link defaults. + $links['comment-' . $link] = $link_attributes + array( + 'html' => TRUE, + ); + } + } + $elements = array( + '#theme' => 'links__entity__comment__' . $field_name, + '#links' => $links, + '#attributes' => array('class' => array('links', 'inline')), + ); + + return $elements; + } + +} diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index f2e734f..dc2e4a8 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -30,7 +30,7 @@ function testCommentInterface() { $this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentForm(TRUE); $this->setCommentSubject(FALSE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $this->drupalLogout(); // Post comment #1 without subject or preview. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php index f8a8afd..34a1021 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNodeAccessTest.php @@ -57,7 +57,7 @@ function testThreadedCommentView() { $this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentForm(TRUE); $this->setCommentSubject(TRUE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $this->drupalLogout(); // Post comment. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php index 55e7b54..15aad21 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPagerTest.php @@ -37,7 +37,7 @@ function testCommentPaging() { $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE); $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); // Set comments to one per page so that we are able to test paging without // needing to insert large numbers of comments. @@ -77,7 +77,7 @@ function testCommentPaging() { // If we switch to threaded mode, the replies on the oldest comment // should be bumped to the first page and comment 6 should be bumped // to the second page. - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); $this->drupalGet('node/' . $node->nid, array('query' => array('page' => 0))); $this->assertTrue($this->commentExists($reply, TRUE), 'In threaded mode, reply appears on page 1.'); $this->assertFalse($this->commentExists($comments[1]), 'In threaded mode, comment 2 has been bumped off of page 1.'); @@ -137,7 +137,7 @@ function testCommentOrderingThreading() { // - 2 // - 5 - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); $expected_order = array( 0, @@ -151,7 +151,7 @@ function testCommentOrderingThreading() { $this->drupalGet('node/' . $node->nid); $this->assertCommentOrder($comments, $expected_order); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); $expected_order = array( 0, @@ -232,7 +232,7 @@ function testCommentNewPageIndicator() { // - 2 // - 5 - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_FLAT, 'Comment paging changed.'); $expected_pages = array( 1 => 5, // Page of comment 5 @@ -250,7 +250,7 @@ function testCommentNewPageIndicator() { $this->assertIdentical($expected_page, $returned_page, format_string('Flat mode, @new replies: expected page @expected, returned page @returned.', array('@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page))); } - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.'); $expected_pages = array( 1 => 5, // Page of comment 5 diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index faf6ace..69b59ca 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -40,7 +40,7 @@ function testCommentPreview() { $this->setCommentPreview(DRUPAL_OPTIONAL); $this->setCommentForm(TRUE); $this->setCommentSubject(TRUE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $this->drupalLogout(); // Login as web user and add a signature and a user picture. @@ -77,7 +77,7 @@ function testCommentPreview() { /** * Tests comment edit, preview, and save. - */ + * function testCommentEditPreviewSave() { $langcode = LANGUAGE_NOT_SPECIFIED; $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval')); @@ -85,7 +85,7 @@ function testCommentEditPreviewSave() { $this->setCommentPreview(DRUPAL_OPTIONAL); $this->setCommentForm(TRUE); $this->setCommentSubject(TRUE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $edit = array(); $date = new DrupalDateTime('2008-03-02 17:23'); @@ -143,6 +143,6 @@ function testCommentEditPreviewSave() { $this->assertEqual($comment_loaded->name->value, $edit['name'], 'Name loaded.'); $this->assertEqual($comment_loaded->created->value, $raw_date, 'Date loaded.'); - } + }*/ } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php index 77b5efd..9dc76a4 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentStatisticsTest.php @@ -44,7 +44,7 @@ function testCommentNodeCommentStatistics() { $this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentForm(TRUE); $this->setCommentSubject(FALSE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $this->drupalLogout(); // Checks the initial values of node comment statistics with no comment. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php index c11d2d4..e46956a 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php @@ -232,7 +232,7 @@ function setCommentPreview($mode) { * comments; FALSE if it should be displayed on its own page. */ function setCommentForm($enabled) { - $this->setCommentSettings('comment_form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); + $this->setWidgetSettings('form_location', ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.'); } /** @@ -255,7 +255,27 @@ function setCommentAnonymous($level) { * Comments per page value. */ function setCommentsPerPage($number) { - $this->setCommentSettings('comment_default_per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number))); + $this->setWidgetSettings('per_page', $number, format_string('Number of comments per page set to @number.', array('@number' => $number))); + } + + /** + * Sets a comment widget settings for the article content type. + * + * @param string $name + * Name of variable. + * @param string $value + * Value of variable. + * @param string $message + * Status message to display. + */ + function setWidgetSettings($name, $value, $message) { + $display = entity_get_display('node', 'article', 'default'); + $settings = $display->getComponent('comment'); + $settings['settings'][$name] = $value; + $display + ->setComponent('comment', $settings) + ->save(); + $this->pass($message); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php index 27d5fb3..c8fa3fc 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php @@ -29,7 +29,7 @@ function testCommentThreading() { $this->setCommentPreview(DRUPAL_DISABLED); $this->setCommentForm(TRUE); $this->setCommentSubject(TRUE); - $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); + $this->setWidgetSettings('default_mode', COMMENT_MODE_THREADED, 'Comment paging changed.'); $this->drupalLogout(); // Create a node. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index dbd9e87..55e3321 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -92,9 +92,9 @@ protected function createEntity($values, $langcode, $bundle_name = 'comment_arti } $node = $this->drupalCreateNode(array( 'type' => $node_type, - $field_name => array(LANGUAGE_NOT_SPECIFIED => array( - array('status' => COMMENT_OPEN) - )), + $field_name => array(LANGUAGE_NOT_SPECIFIED => array( + array('status' => COMMENT_OPEN) + )), )); $values['entity_id'] = $node->nid; $values['entity_type'] = 'node'; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php index 2bd88aa..83b8fab 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentUserTest.php @@ -84,6 +84,9 @@ function setUp() { 'post comments', 'skip comment approval', )); + + $this->web_user->comment = array(LANGUAGE_NOT_SPECIFIED => array(array('status' => COMMENT_OPEN))); + $this->web_user->save(); } /** diff --git a/core/modules/comment/lib/Drupal/comment/Type/CommentNewItem.php b/core/modules/comment/lib/Drupal/comment/Type/CommentNewItem.php new file mode 100644 index 0000000..c1b215f --- /dev/null +++ b/core/modules/comment/lib/Drupal/comment/Type/CommentNewItem.php @@ -0,0 +1,40 @@ + 'integer', + 'label' => t('Integer value'), + 'class' => '\Drupal\comment\FieldNewValue', + ); + } + return static::$propertyDefinitions; + } +}