Mercurial > hg > isophonics-drupal-site
comparison core/modules/comment/src/CommentLazyBuilders.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | 1 <?php |
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\Core\DependencyInjection\DeprecatedServicePropertyTrait; | |
6 use Drupal\Core\Entity\EntityFormBuilderInterface; | 7 use Drupal\Core\Entity\EntityFormBuilderInterface; |
7 use Drupal\Core\Entity\EntityInterface; | 8 use Drupal\Core\Entity\EntityInterface; |
8 use Drupal\Core\Entity\EntityManagerInterface; | 9 use Drupal\Core\Entity\EntityTypeManagerInterface; |
9 use Drupal\Core\Extension\ModuleHandlerInterface; | 10 use Drupal\Core\Extension\ModuleHandlerInterface; |
10 use Drupal\Core\Render\RendererInterface; | 11 use Drupal\Core\Render\RendererInterface; |
11 use Drupal\Core\Session\AccountInterface; | 12 use Drupal\Core\Session\AccountInterface; |
12 use Drupal\Core\Url; | 13 use Drupal\Core\Url; |
13 | 14 |
14 /** | 15 /** |
15 * Defines a service for comment #lazy_builder callbacks. | 16 * Defines a service for comment #lazy_builder callbacks. |
16 */ | 17 */ |
17 class CommentLazyBuilders { | 18 class CommentLazyBuilders { |
18 | 19 use DeprecatedServicePropertyTrait; |
19 /** | 20 |
20 * The entity manager service. | 21 /** |
21 * | 22 * {@inheritdoc} |
22 * @var \Drupal\Core\Entity\EntityManagerInterface | 23 */ |
23 */ | 24 protected $deprecatedProperties = ['entityManager' => 'entity.manager']; |
24 protected $entityManager; | 25 |
26 /** | |
27 * The entity type manager service. | |
28 * | |
29 * @var \Drupal\Core\Entity\EntityTypeManagerInterface | |
30 */ | |
31 protected $entityTypeManager; | |
25 | 32 |
26 /** | 33 /** |
27 * The entity form builder service. | 34 * The entity form builder service. |
28 * | 35 * |
29 * @var \Drupal\Core\Entity\EntityFormBuilderInterface | 36 * @var \Drupal\Core\Entity\EntityFormBuilderInterface |
59 protected $renderer; | 66 protected $renderer; |
60 | 67 |
61 /** | 68 /** |
62 * Constructs a new CommentLazyBuilders object. | 69 * Constructs a new CommentLazyBuilders object. |
63 * | 70 * |
64 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | 71 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
65 * The entity manager service. | 72 * The entity type manager service. |
66 * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder | 73 * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder |
67 * The entity form builder service. | 74 * The entity form builder service. |
68 * @param \Drupal\Core\Session\AccountInterface $current_user | 75 * @param \Drupal\Core\Session\AccountInterface $current_user |
69 * The current logged in user. | 76 * The current logged in user. |
70 * @param \Drupal\comment\CommentManagerInterface $comment_manager | 77 * @param \Drupal\comment\CommentManagerInterface $comment_manager |
72 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | 79 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
73 * The module handler service. | 80 * The module handler service. |
74 * @param \Drupal\Core\Render\RendererInterface $renderer | 81 * @param \Drupal\Core\Render\RendererInterface $renderer |
75 * The renderer service. | 82 * The renderer service. |
76 */ | 83 */ |
77 public function __construct(EntityManagerInterface $entity_manager, EntityFormBuilderInterface $entity_form_builder, AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer) { | 84 public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFormBuilderInterface $entity_form_builder, AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer) { |
78 $this->entityManager = $entity_manager; | 85 $this->entityTypeManager = $entity_type_manager; |
79 $this->entityFormBuilder = $entity_form_builder; | 86 $this->entityFormBuilder = $entity_form_builder; |
80 $this->currentUser = $current_user; | 87 $this->currentUser = $current_user; |
81 $this->commentManager = $comment_manager; | 88 $this->commentManager = $comment_manager; |
82 $this->moduleHandler = $module_handler; | 89 $this->moduleHandler = $module_handler; |
83 $this->renderer = $renderer; | 90 $this->renderer = $renderer; |
104 'entity_id' => $commented_entity_id, | 111 'entity_id' => $commented_entity_id, |
105 'field_name' => $field_name, | 112 'field_name' => $field_name, |
106 'comment_type' => $comment_type_id, | 113 'comment_type' => $comment_type_id, |
107 'pid' => NULL, | 114 'pid' => NULL, |
108 ]; | 115 ]; |
109 $comment = $this->entityManager->getStorage('comment')->create($values); | 116 $comment = $this->entityTypeManager->getStorage('comment')->create($values); |
110 return $this->entityFormBuilder->getForm($comment); | 117 return $this->entityFormBuilder->getForm($comment); |
111 } | 118 } |
112 | 119 |
113 /** | 120 /** |
114 * #lazy_builder callback; builds a comment's links. | 121 * #lazy_builder callback; builds a comment's links. |
132 '#attributes' => ['class' => ['links', 'inline']], | 139 '#attributes' => ['class' => ['links', 'inline']], |
133 ]; | 140 ]; |
134 | 141 |
135 if (!$is_in_preview) { | 142 if (!$is_in_preview) { |
136 /** @var \Drupal\comment\CommentInterface $entity */ | 143 /** @var \Drupal\comment\CommentInterface $entity */ |
137 $entity = $this->entityManager->getStorage('comment')->load($comment_entity_id); | 144 $entity = $this->entityTypeManager->getStorage('comment')->load($comment_entity_id); |
138 $commented_entity = $entity->getCommentedEntity(); | 145 $commented_entity = $entity->getCommentedEntity(); |
139 | 146 |
140 $links['comment'] = $this->buildLinks($entity, $commented_entity); | 147 $links['comment'] = $this->buildLinks($entity, $commented_entity); |
141 | 148 |
142 // Allow other modules to alter the comment links. | 149 // Allow other modules to alter the comment links. |
167 | 174 |
168 if ($status == CommentItemInterface::OPEN) { | 175 if ($status == CommentItemInterface::OPEN) { |
169 if ($entity->access('delete')) { | 176 if ($entity->access('delete')) { |
170 $links['comment-delete'] = [ | 177 $links['comment-delete'] = [ |
171 'title' => t('Delete'), | 178 'title' => t('Delete'), |
172 'url' => $entity->urlInfo('delete-form'), | 179 'url' => $entity->toUrl('delete-form'), |
173 ]; | 180 ]; |
174 } | 181 } |
175 | 182 |
176 if ($entity->access('update')) { | 183 if ($entity->access('update')) { |
177 $links['comment-edit'] = [ | 184 $links['comment-edit'] = [ |
178 'title' => t('Edit'), | 185 'title' => t('Edit'), |
179 'url' => $entity->urlInfo('edit-form'), | 186 'url' => $entity->toUrl('edit-form'), |
180 ]; | 187 ]; |
181 } | 188 } |
182 if ($entity->access('create')) { | 189 if ($entity->access('create')) { |
183 $links['comment-reply'] = [ | 190 $links['comment-reply'] = [ |
184 'title' => t('Reply'), | 191 'title' => t('Reply'), |
203 | 210 |
204 // Add translations link for translation-enabled comment bundles. | 211 // Add translations link for translation-enabled comment bundles. |
205 if ($this->moduleHandler->moduleExists('content_translation') && $this->access($entity)->isAllowed()) { | 212 if ($this->moduleHandler->moduleExists('content_translation') && $this->access($entity)->isAllowed()) { |
206 $links['comment-translations'] = [ | 213 $links['comment-translations'] = [ |
207 'title' => t('Translate'), | 214 'title' => t('Translate'), |
208 'url' => $entity->urlInfo('drupal:content-translation-overview'), | 215 'url' => $entity->toUrl('drupal:content-translation-overview'), |
209 ]; | 216 ]; |
210 } | 217 } |
211 | 218 |
212 return [ | 219 return [ |
213 '#theme' => 'links__comment__comment', | 220 '#theme' => 'links__comment__comment', |