Issue #3240167 by andypost, alexpott, daffie, larowlan: \Drupal\comment\CommentStorage::getMaxThread() and \Drupal\comment\Entity\Comment::getThread() cause deprecations on PHP 8.1

merge-requests/1289/head
catch 2021-10-04 16:07:16 +01:00
parent 0867d5a4a9
commit 6fb2c098e3
4 changed files with 11 additions and 8 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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

View File

@ -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]);