diff --git a/core/modules/comment/src/CommentInterface.php b/core/modules/comment/src/CommentInterface.php index 6cc36850998d..055c875c30bb 100644 --- a/core/modules/comment/src/CommentInterface.php +++ b/core/modules/comment/src/CommentInterface.php @@ -211,8 +211,9 @@ interface CommentInterface extends ContentEntityInterface, EntityChangedInterfac /** * Returns the alphadecimal representation of the comment's place in a thread. * - * @return string - * The alphadecimal representation of the comment's place in a thread. + * @return string|null + * The alphadecimal representation of the comment's place in a thread. NULL + * is returned before a comment is saved. */ public function getThread(); diff --git a/core/modules/comment/src/CommentStorageInterface.php b/core/modules/comment/src/CommentStorageInterface.php index 592b1ea92159..764a5e4a9b95 100644 --- a/core/modules/comment/src/CommentStorageInterface.php +++ b/core/modules/comment/src/CommentStorageInterface.php @@ -17,9 +17,10 @@ interface CommentStorageInterface extends ContentEntityStorageInterface { * @param \Drupal\comment\CommentInterface $comment * A comment entity. * - * @return string + * @return string|null * The maximum encoded thread value among the top level comments of the - * node $comment belongs to. + * node $comment belongs to. NULL is returned when the commented entity has + * no comments. */ public function getMaxThread(CommentInterface $comment); @@ -29,8 +30,9 @@ interface CommentStorageInterface extends ContentEntityStorageInterface { * @param \Drupal\comment\CommentInterface $comment * A comment entity. * - * @return string - * The maximum encoded thread value among all replies of $comment. + * @return string|null + * The maximum encoded thread value among all replies of $comment. NULL is + * returned when the commented entity has no comments. */ public function getMaxThreadPerThread(CommentInterface $comment); diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php index e2da95b850ab..0e4e024dd574 100644 --- a/core/modules/comment/src/CommentViewBuilder.php +++ b/core/modules/comment/src/CommentViewBuilder.php @@ -124,7 +124,7 @@ class CommentViewBuilder extends EntityViewBuilder { foreach ($entities as $id => $entity) { if ($build[$id]['#comment_threaded']) { - $comment_indent = count(explode('.', $entity->getThread())) - 1; + $comment_indent = count(explode('.', (string) $entity->getThread())) - 1; if ($comment_indent > $current_indent) { // Set 1 to indent this comment from the previous one (its parent). // Set only one extra level of indenting even if the difference in diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 8da909c50352..2fc615f30808 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -102,7 +102,7 @@ class Comment extends ContentEntityBase implements CommentInterface { // by retrieving the maximum thread level. $max = $storage->getMaxThread($this); // Strip the "/" from the end of the thread. - $max = rtrim($max, '/'); + $max = rtrim((string) $max, '/'); // We need to get the value at the correct depth. $parts = explode('.', $max); $n = Number::alphadecimalToInt($parts[0]);