comparison core/modules/comment/src/CommentLinkBuilder.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
2 2
3 namespace Drupal\comment; 3 namespace Drupal\comment;
4 4
5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; 5 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
6 use Drupal\Component\Utility\NestedArray; 6 use Drupal\Component\Utility\NestedArray;
7 use Drupal\Core\Entity\EntityManagerInterface; 7 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
8 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Entity\FieldableEntityInterface; 9 use Drupal\Core\Entity\FieldableEntityInterface;
9 use Drupal\Core\Extension\ModuleHandlerInterface; 10 use Drupal\Core\Extension\ModuleHandlerInterface;
10 use Drupal\Core\Session\AccountInterface; 11 use Drupal\Core\Session\AccountInterface;
11 use Drupal\Core\StringTranslation\StringTranslationTrait; 12 use Drupal\Core\StringTranslation\StringTranslationTrait;
12 use Drupal\Core\StringTranslation\TranslationInterface; 13 use Drupal\Core\StringTranslation\TranslationInterface;
18 * Comment links include 'log in to post new comment', 'add new comment' etc. 19 * Comment links include 'log in to post new comment', 'add new comment' etc.
19 */ 20 */
20 class CommentLinkBuilder implements CommentLinkBuilderInterface { 21 class CommentLinkBuilder implements CommentLinkBuilderInterface {
21 22
22 use StringTranslationTrait; 23 use StringTranslationTrait;
24 use DeprecatedServicePropertyTrait;
25
26 /**
27 * {@inheritdoc}
28 */
29 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
23 30
24 /** 31 /**
25 * Current user. 32 * Current user.
26 * 33 *
27 * @var \Drupal\Core\Session\AccountInterface 34 * @var \Drupal\Core\Session\AccountInterface
41 * @var \Drupal\Core\Extension\ModuleHandlerInterface 48 * @var \Drupal\Core\Extension\ModuleHandlerInterface
42 */ 49 */
43 protected $moduleHandler; 50 protected $moduleHandler;
44 51
45 /** 52 /**
46 * The entity manager service. 53 * The entity type manager service.
47 * 54 *
48 * @var \Drupal\Core\Entity\EntityManagerInterface 55 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
49 */ 56 */
50 protected $entityManager; 57 protected $entityTypeManager;
51 58
52 /** 59 /**
53 * Constructs a new CommentLinkBuilder object. 60 * Constructs a new CommentLinkBuilder object.
54 * 61 *
55 * @param \Drupal\Core\Session\AccountInterface $current_user 62 * @param \Drupal\Core\Session\AccountInterface $current_user
58 * Comment manager service. 65 * Comment manager service.
59 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler 66 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
60 * Module handler service. 67 * Module handler service.
61 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation 68 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
62 * String translation service. 69 * String translation service.
63 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager 70 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
64 * The entity manager service. 71 * The entity type manager.
65 */ 72 */
66 public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityManagerInterface $entity_manager) { 73 public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager) {
67 $this->currentUser = $current_user; 74 $this->currentUser = $current_user;
68 $this->commentManager = $comment_manager; 75 $this->commentManager = $comment_manager;
69 $this->moduleHandler = $module_handler; 76 $this->moduleHandler = $module_handler;
70 $this->stringTranslation = $string_translation; 77 $this->stringTranslation = $string_translation;
71 $this->entityManager = $entity_manager; 78 $this->entityTypeManager = $entity_type_manager;
72 } 79 }
73 80
74 /** 81 /**
75 * {@inheritdoc} 82 * {@inheritdoc}
76 */ 83 */
199 // Embed the metadata for the "X new comments" link (if any) on this 206 // Embed the metadata for the "X new comments" link (if any) on this
200 // entity. 207 // entity.
201 $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id()); 208 $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id());
202 $new_comments = $this->commentManager->getCountNewComments($entity); 209 $new_comments = $this->commentManager->getCountNewComments($entity);
203 if ($new_comments > 0) { 210 if ($new_comments > 0) {
204 $page_number = $this->entityManager 211 $page_number = $this->entityTypeManager
205 ->getStorage('comment') 212 ->getStorage('comment')
206 ->getNewCommentPageNumber($entity->{$field_name}->comment_count, $new_comments, $entity, $field_name); 213 ->getNewCommentPageNumber($entity->{$field_name}->comment_count, $new_comments, $entity, $field_name);
207 $query = $page_number ? ['page' => $page_number] : NULL; 214 $query = $page_number ? ['page' => $page_number] : NULL;
208 $value = [ 215 $value = [
209 'new_comment_count' => (int) $new_comments, 216 'new_comment_count' => (int) $new_comments,
210 'first_new_comment_link' => $entity->url('canonical', [ 217 'first_new_comment_link' => $entity->toUrl('canonical', [
211 'query' => $query, 218 'query' => $query,
212 'fragment' => 'new', 219 'fragment' => 'new',
213 ]), 220 ])->toString(),
214 ]; 221 ];
215 $parents = ['comment', 'newCommentsLinks', $entity->getEntityTypeId(), $field_name, $entity->id()]; 222 $parents = ['comment', 'newCommentsLinks', $entity->getEntityTypeId(), $field_name, $entity->id()];
216 NestedArray::setValue($entity_links['comment__' . $field_name]['#attached']['drupalSettings'], $parents, $value); 223 NestedArray::setValue($entity_links['comment__' . $field_name]['#attached']['drupalSettings'], $parents, $value);
217 } 224 }
218 } 225 }