comparison core/modules/comment/comment.module @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
77 $output = '<h3>' . t('About') . '</h3>'; 77 $output = '<h3>' . t('About') . '</h3>';
78 $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href=":comment">online documentation for the Comment module</a>.', [':comment' => 'https://www.drupal.org/documentation/modules/comment']) . '</p>'; 78 $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href=":comment">online documentation for the Comment module</a>.', [':comment' => 'https://www.drupal.org/documentation/modules/comment']) . '</p>';
79 $output .= '<h3>' . t('Uses') . '</h3>'; 79 $output .= '<h3>' . t('Uses') . '</h3>';
80 $output .= '<dl>'; 80 $output .= '<dl>';
81 $output .= '<dt>' . t('Enabling commenting') . '</dt>'; 81 $output .= '<dt>' . t('Enabling commenting') . '</dt>';
82 $output .= '<dd>' . t('Comment functionality can be enabled for any entity sub-type (for example, a <a href=":content-type">content type</a>) by adding a <em>Comments</em> field on its <em>Manage fields page</em>. Adding or removing commenting for an entity through the user interface requires the <a href=":field_ui">Field UI</a> module to be enabled, even though the commenting functionality works without it. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', [':content-type' => (\Drupal::moduleHandler()->moduleExists('node')) ? \Drupal::url('entity.node_type.collection') : '#', ':field' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#']) . '</dd>'; 82 $output .= '<dd>' . t('Comment functionality can be enabled for any entity sub-type (for example, a <a href=":content-type">content type</a>) by adding a <em>Comments</em> field on its <em>Manage fields page</em>. Adding or removing commenting for an entity through the user interface requires the <a href=":field_ui">Field UI</a> module to be enabled, even though the commenting functionality works without it. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', [':content-type' => (\Drupal::moduleHandler()->moduleExists('node')) ? Url::fromRoute('entity.node_type.collection')->toString() : '#', ':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#']) . '</dd>';
83 $output .= '<dt>' . t('Configuring commenting settings') . '</dt>'; 83 $output .= '<dt>' . t('Configuring commenting settings') . '</dt>';
84 $output .= '<dd>' . t('Commenting settings can be configured by editing the <em>Comments</em> field on the <em>Manage fields page</em> of an entity type if the <em>Field UI module</em> is enabled. Configuration includes the label of the comments field, the number of comments to be displayed, and whether they are shown in threaded list. Commenting can be be configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. Changing this configuration for an entity type will not change existing entity items.') . '</dd>'; 84 $output .= '<dd>' . t('Commenting settings can be configured by editing the <em>Comments</em> field on the <em>Manage fields page</em> of an entity type if the <em>Field UI module</em> is enabled. Configuration includes the label of the comments field, the number of comments to be displayed, and whether they are shown in threaded list. Commenting can be be configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. Changing this configuration for an entity type will not change existing entity items.') . '</dd>';
85 $output .= '<dt>' . t('Overriding default settings') . '</dt>'; 85 $output .= '<dt>' . t('Overriding default settings') . '</dt>';
86 $output .= '<dd>' . t('Users with the appropriate permissions can override the default commenting settings of an entity type when they create an item of that type.') . '</dd>'; 86 $output .= '<dd>' . t('Users with the appropriate permissions can override the default commenting settings of an entity type when they create an item of that type.') . '</dd>';
87 $output .= '<dt>' . t('Adding comment types') . '</dt>'; 87 $output .= '<dt>' . t('Adding comment types') . '</dt>';
88 $output .= '<dd>' . t('Additional <em>comment types</em> can be created per entity sub-type and added on the <a href=":field">Comment types page</a>. If there are multiple comment types available you can select the appropriate one after adding a <em>Comments field</em>.', [':field' => \Drupal::url('entity.comment_type.collection')]) . '</dd>'; 88 $output .= '<dd>' . t('Additional <em>comment types</em> can be created per entity sub-type and added on the <a href=":field">Comment types page</a>. If there are multiple comment types available you can select the appropriate one after adding a <em>Comments field</em>.', [':field' => Url::fromRoute('entity.comment_type.collection')->toString()]) . '</dd>';
89 $output .= '<dt>' . t('Approving and managing comments') . '</dt>'; 89 $output .= '<dt>' . t('Approving and managing comments') . '</dt>';
90 $output .= '<dd>' . t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href=":comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href=":admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', [':comment-approval' => \Drupal::url('comment.admin_approval'), ':admin-comment' => \Drupal::url('comment.admin')]) . '</dd>'; 90 $output .= '<dd>' . t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href=":comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href=":admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', [':comment-approval' => Url::fromRoute('comment.admin_approval')->toString(), ':admin-comment' => Url::fromRoute('comment.admin')->toString()]) . '</dd>';
91 $output .= '</dl>'; 91 $output .= '</dl>';
92 return $output; 92 return $output;
93 93
94 case 'entity.comment_type.collection': 94 case 'entity.comment_type.collection':
95 $output = '<p>' . t('This page provides a list of all comment types on the site and allows you to manage the fields, form and display settings for each.') . '</p>'; 95 $output = '<p>' . t('This page provides a list of all comment types on the site and allows you to manage the fields, form and display settings for each.') . '</p>';
238 'fragment' => 'comments', 238 'fragment' => 'comments',
239 'absolute' => TRUE, 239 'absolute' => TRUE,
240 ]; 240 ];
241 $entity->rss_elements[] = [ 241 $entity->rss_elements[] = [
242 'key' => 'comments', 242 'key' => 'comments',
243 'value' => $entity->url('canonical', $options), 243 'value' => $entity->toUrl('canonical', $options)->toString(),
244 ]; 244 ];
245 } 245 }
246 } 246 }
247 } 247 }
248 } 248 }
621 * An associative array containing: 621 * An associative array containing:
622 * - elements: An associative array containing the comment and entity objects. 622 * - elements: An associative array containing the comment and entity objects.
623 * Array keys: #comment, #commented_entity. 623 * Array keys: #comment, #commented_entity.
624 */ 624 */
625 function template_preprocess_comment(&$variables) { 625 function template_preprocess_comment(&$variables) {
626 /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
627 $date_formatter = \Drupal::service('date.formatter');
626 /** @var \Drupal\comment\CommentInterface $comment */ 628 /** @var \Drupal\comment\CommentInterface $comment */
627 $comment = $variables['elements']['#comment']; 629 $comment = $variables['elements']['#comment'];
628 $commented_entity = $comment->getCommentedEntity(); 630 $commented_entity = $comment->getCommentedEntity();
629 $variables['comment'] = $comment; 631 $variables['comment'] = $comment;
630 $variables['commented_entity'] = $commented_entity; 632 $variables['commented_entity'] = $commented_entity;
636 '#account' => $account, 638 '#account' => $account,
637 ]; 639 ];
638 $variables['author'] = \Drupal::service('renderer')->render($username); 640 $variables['author'] = \Drupal::service('renderer')->render($username);
639 $variables['author_id'] = $comment->getOwnerId(); 641 $variables['author_id'] = $comment->getOwnerId();
640 $variables['new_indicator_timestamp'] = $comment->getChangedTime(); 642 $variables['new_indicator_timestamp'] = $comment->getChangedTime();
641 $variables['created'] = format_date($comment->getCreatedTime()); 643 $variables['created'] = $date_formatter->format($comment->getCreatedTime());
642 // Avoid calling format_date() twice on the same timestamp. 644 // Avoid calling DateFormatterInterface::format() twice on the same timestamp.
643 if ($comment->getChangedTime() == $comment->getCreatedTime()) { 645 if ($comment->getChangedTime() == $comment->getCreatedTime()) {
644 $variables['changed'] = $variables['created']; 646 $variables['changed'] = $variables['created'];
645 } 647 }
646 else { 648 else {
647 $variables['changed'] = format_date($comment->getChangedTime()); 649 $variables['changed'] = $date_formatter->format($comment->getChangedTime());
648 } 650 }
649 651
650 if (theme_get_setting('features.comment_user_picture')) { 652 if (theme_get_setting('features.comment_user_picture')) {
651 // To change user picture settings (for instance, image style), edit the 653 // To change user picture settings (for instance, image style), edit the
652 // 'compact' view mode on the User entity. 654 // 'compact' view mode on the User entity.
680 $username = [ 682 $username = [
681 '#theme' => 'username', 683 '#theme' => 'username',
682 '#account' => $account_parent, 684 '#account' => $account_parent,
683 ]; 685 ];
684 $variables['parent_author'] = \Drupal::service('renderer')->render($username); 686 $variables['parent_author'] = \Drupal::service('renderer')->render($username);
685 $variables['parent_created'] = format_date($comment_parent->getCreatedTime()); 687 $variables['parent_created'] = $date_formatter->format($comment_parent->getCreatedTime());
686 // Avoid calling format_date() twice on the same timestamp. 688 // Avoid calling DateFormatterInterface::format() twice on same timestamp.
687 if ($comment_parent->getChangedTime() == $comment_parent->getCreatedTime()) { 689 if ($comment_parent->getChangedTime() == $comment_parent->getCreatedTime()) {
688 $variables['parent_changed'] = $variables['parent_created']; 690 $variables['parent_changed'] = $variables['parent_created'];
689 } 691 }
690 else { 692 else {
691 $variables['parent_changed'] = format_date($comment_parent->getChangedTime()); 693 $variables['parent_changed'] = $date_formatter->format($comment_parent->getChangedTime());
692 } 694 }
693 $permalink_uri_parent = $comment_parent->permalink(); 695 $permalink_uri_parent = $comment_parent->permalink();
694 $attributes = $permalink_uri_parent->getOption('attributes') ?: []; 696 $attributes = $permalink_uri_parent->getOption('attributes') ?: [];
695 $attributes += ['class' => ['permalink'], 'rel' => 'bookmark']; 697 $attributes += ['class' => ['permalink'], 'rel' => 'bookmark'];
696 $permalink_uri_parent->setOption('attributes', $attributes); 698 $permalink_uri_parent->setOption('attributes', $attributes);
722 $variables['status'] = $comment->isPublished() ? 'published' : 'unpublished'; 724 $variables['status'] = $comment->isPublished() ? 'published' : 'unpublished';
723 } 725 }
724 726
725 // Add comment author user ID. Necessary for the comment-by-viewer library. 727 // Add comment author user ID. Necessary for the comment-by-viewer library.
726 $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId(); 728 $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId();
729 // Add anchor for each comment.
730 $variables['attributes']['id'] = 'comment-' . $comment->id();
727 } 731 }
728 732
729 /** 733 /**
730 * Prepares variables for comment field templates. 734 * Prepares variables for comment field templates.
731 * 735 *