Mercurial > hg > isophonics-drupal-site
diff core/modules/comment/src/CommentForm.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/core/modules/comment/src/CommentForm.php Tue Jul 10 15:07:59 2018 +0100 +++ b/core/modules/comment/src/CommentForm.php Thu Feb 28 13:21:36 2019 +0000 @@ -9,7 +9,8 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\EntityConstraintViolationListInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RendererInterface; @@ -38,23 +39,31 @@ protected $renderer; /** + * The entity field manager. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface + */ + protected $entityFieldManager; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity.repository'), $container->get('current_user'), $container->get('renderer'), $container->get('entity_type.bundle.info'), - $container->get('datetime.time') + $container->get('datetime.time'), + $container->get('entity_field.manager') ); } /** * Constructs a new CommentForm. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository. * @param \Drupal\Core\Session\AccountInterface $current_user * The current user. * @param \Drupal\Core\Render\RendererInterface $renderer @@ -64,10 +73,11 @@ * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. */ - public function __construct(EntityManagerInterface $entity_manager, AccountInterface $current_user, RendererInterface $renderer, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) { - parent::__construct($entity_manager, $entity_type_bundle_info, $time); + public function __construct(EntityRepositoryInterface $entity_repository, AccountInterface $current_user, RendererInterface $renderer, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { + parent::__construct($entity_repository, $entity_type_bundle_info, $time); $this->currentUser = $current_user; $this->renderer = $renderer; + $this->entityFieldManager = $entity_field_manager ?: \Drupal::service('entity_field.manager'); } /** @@ -76,9 +86,9 @@ public function form(array $form, FormStateInterface $form_state) { /** @var \Drupal\comment\CommentInterface $comment */ $comment = $this->entity; - $entity = $this->entityManager->getStorage($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId()); + $entity = $this->entityTypeManager->getStorage($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId()); $field_name = $comment->getFieldName(); - $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()]; + $field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()]; $config = $this->config('user.settings'); // In several places within this function, we vary $form on: @@ -369,22 +379,22 @@ // Add a log entry. $logger->notice('Comment posted: %subject.', [ '%subject' => $comment->getSubject(), - 'link' => $this->l(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id())) + 'link' => $this->l(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id())), ]); // Explain the approval queue if necessary. if (!$comment->isPublished()) { if (!$this->currentUser->hasPermission('administer comments')) { - drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.')); + $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.')); } } else { - drupal_set_message($this->t('Your comment has been posted.')); + $this->messenger()->addStatus($this->t('Your comment has been posted.')); } $query = []; // Find the current display page for this comment. - $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name]; - $page = $this->entityManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page')); + $field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$field_name]; + $page = $this->entityTypeManager->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page')); if ($page > 0) { $query['page'] = $page; } @@ -394,7 +404,7 @@ } else { $logger->warning('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]); - drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]), 'error'); + $this->messenger()->addError($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()])); // Redirect the user to the entity they are commenting on. } $form_state->setRedirectUrl($uri);