Problem/Motivation

This functions are just procedural wrappers around entity_view() and should be marked as @deprecated for #2205673: [META] Remove all @deprecated functions marked "remove before 8.0"

Proposed resolution

1) remove usage of comment_view()
2) mark @deprecated for 8.x comment_view() and comment_view_multiple() and propose removal before 9.x

Remaining tasks

Decide on comment_preview() should be marked as @api for #2116841: [policy] Decide what the Drupal Public API should be and how to manage it

User interface changes

no

API changes

no

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because clean-up usage of wrapper functions
Issue priority Normal because clarifies usage of API and improves DX
Disruption Non-disruptive

Comments

pguillard’s picture

Status: Active » Needs review
StatusFileSize
new3.71 KB

Here is a patch. Hope it goes to the right direction.

andypost’s picture

yep, looks great!

  1. +++ b/core/modules/comment/comment.module
    @@ -553,7 +555,7 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta
    +    $comment_build = entity_view($comment, 'full', NULL);
    
    @@ -563,7 +565,7 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta
    +      $build = entity_view($parent, 'full', NULL);
    
    +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php
    @@ -27,7 +27,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase {
    +    $build = entity_view($comment, 'full', NULL);
    
    +++ b/core/modules/comment/src/Plugin/views/row/Rss.php
    @@ -106,7 +106,7 @@ public function render($row) {
    +    $build = entity_view($comment, 'rss', NULL);
    

    NULL is not needed

  2. +++ b/core/modules/comment/src/Entity/Comment.php
    @@ -80,8 +80,7 @@ public function preSave(EntityStorageInterface $storage) {
    +      // Add the comment to database. This next section builds the thread field..
    

    nit, extra dot at the end

pguillard’s picture

StatusFileSize
new3.57 KB
new2.45 KB

Thanks @andypost.
A new patch with your corrections.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

looks good now, let's get commiter feedback on this

webchick’s picture

Issue tags: +Needs beta evaluation

Tagging for beta evaluation. Also, I was under the general impression we weren't marking new APIs that hadn't previously been marked @deprecated deprecated for 8.0, and instead these would be in core now until 9.0. Maybe xjm/alexpott would be able to corroborate this or not.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/comment/comment.module
@@ -232,6 +232,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 8.0

@@ -253,6 +254,7 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 8.0

These should be deprecated for 9.0 now. Also I'm not convinced that this passes the beta evaluation which it still needs.

pguillard’s picture

StatusFileSize
new3.56 KB
new955 bytes

Updated.
I guess it is not appropriate to set it to RTBC ? cause it may not pass the beta evaluation.

pguillard’s picture

Status: Needs work » Needs review

I have no idea if it passes the beta evaluation... Move to Needs Review

andypost’s picture

Status: Needs review » Needs work

@pguillard we deprecate it in 8.x but will remove in 9.x

+++ b/core/modules/comment/comment.module
@@ -232,6 +232,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
+ * @deprecated in Drupal 9.0.x-dev, will be removed before Drupal 9.0

@@ -253,6 +254,7 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
+ * @deprecated in Drupal 9.0.x-dev, will be removed before Drupal 9.0

Should be @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new3.57 KB
new1.12 KB

Sure..

andypost’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs beta evaluation
Parent issue: » #2116841: [policy] Decide what the Drupal Public API should be and how to manage it
Related issues: -#2116841: [policy] Decide what the Drupal Public API should be and how to manage it

Added beta evaluation

+++ b/core/modules/comment/comment.module
@@ -257,6 +257,7 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0
  */

@@ -278,6 +279,7 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0
  */

You forget to said that entity_view_* should be used instead

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new3.66 KB
new846 bytes

Thanks @andypost, this one with #12 suggestion

andypost’s picture

Status: Needs review » Needs work

take a look at common.inc examples, you missed dots at the end

+++ b/core/modules/comment/comment.module
@@ -257,6 +257,8 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0
+ *   entity_view() should be used instead

@@ -278,6 +280,8 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0
+ *   entity_view_multiple() should be used instead

@deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
Use entity_view() instead.

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new3.63 KB
new1.09 KB

Thank you

Status: Needs review » Needs work

The last submitted patch, 15: deprecate_comment_view-2492585.15.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community

thanx, not it's good to go

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/comment/src/Entity/Comment.php
    @@ -81,7 +81,6 @@ public function preSave(EntityStorageInterface $storage) {
    -      // Also see the documentation for comment_view().
    

    Let's point the new place in the code then that this was intended to point people at. I guess - but perhaps a comment maintainer might have a better idea - that this is meant to point to CommentViewBuilder::buildComponents()

  2. +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php
    @@ -27,7 +27,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase {
    -    $build = comment_view($comment);
    +    $build = entity_view($comment, 'full');
    
    +++ b/core/modules/comment/src/Plugin/views/row/Rss.php
    @@ -106,7 +106,7 @@ public function render($row) {
    -    $build = comment_view($comment, 'rss');
    +    $build = entity_view($comment, 'rss');
    

    Given that these are in plugins I think we can inject the correct service... so inject the view builder. And call ->view().

yarik.lutsiuk’s picture

StatusFileSize
new5.85 KB
new5.85 KB

Fixed all points from #19. Thank You

yarik.lutsiuk’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Suppose now it finally ready

xjm’s picture

Title: Deprecate and remove usage of comment_view() & comment_view_multiple() » Deprecate comment_view() & comment_view_multiple()
Status: Reviewed & tested by the community » Needs work

Thanks everyone for your work on this so far!

In light of #2474151: Mark procedural wrappers in entity.inc as deprecated, maybe we should not convert to entity_view() but instead recommend the entity manager static wrapper?

Also, since this was not already deprecated for removal in 8.0.0 before the beta, we should only mark the wrappers deprecated for now. Removing the usages should probably be postponed during the beta (we can create a followup issue for that for 8.1.x since it is BC-compatible). See https://www.drupal.org/core/beta-changes.

andypost’s picture

This issue should be split into 4 issues, according what @xjm said in IRC about allowed beta changes.

This issue just deprecates functions, next to remove usage
Then 2 tasks:
1) clean-up broken comment
2) use proper service injections into plugins

  1. +++ b/core/modules/comment/src/Entity/Comment.php
    @@ -81,7 +81,7 @@ public function preSave(EntityStorageInterface $storage) {
    -      // Also see the documentation for comment_view().
    +      // @see \Drupal\comment\CommentViewBuilder::buildComponents().
    

    this change should be separate issue 'cos comment_view() docs have nothing about threading

  2. +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php
    @@ -21,14 +25,56 @@
    -    $build = comment_view($comment);
    -    $text = \Drupal::service('renderer')->renderPlain($build);
    +    $build = $this->entityManager->getViewBuilder('comment')->view($comment);
    +    $text = $this->renderer->renderPlain($build);
    
    +++ b/core/modules/comment/src/Plugin/views/row/Rss.php
    @@ -106,7 +106,7 @@ public function render($row) {
    -    $build = comment_view($comment, 'rss');
    +    $build = $this->entityManager->getViewBuilder('comment')->view($comment, 'rss');
    

    this needs separate issue, probably for 8.1.x otoh that minimize code fragility

andypost’s picture

mile23’s picture

Status: Needs review » Reviewed & tested by the community

#25 applies, and 'use' suggestions are good.

It reflects the change in scope of #23, #24.

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @andypost and @Mile23!

This issue only changes documentation, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x.

  • xjm committed 79c11b6 on 8.0.x
    Issue #2492585 by pguillard, yarik.lutsiuk, andypost, Mile23: Deprecate...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.