This functions are only used by the comment entity only but could be useful for contrib

No API changes just deprecate functions and implement similar in Number component

Comments

larowlan’s picture

Good idea

larowlan’s picture

  1. +++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
    @@ -462,4 +462,21 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public static function intToAlphadecimal($i = 0) {
    +    $num = base_convert((int) $i, 10, 36);
    +    $length = strlen($num);
    +
    +    return chr($length + ord('0') - 1) . $num;
    +  }
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  function alphadecimalToInt($c = '00') {
    +    return base_convert(substr($c, 1), 36, 10);
    +  }
    +
    

    Should we be unit testing these, or at the very least opening a followup to do so?

  2. +++ b/core/modules/comment/comment.module
    @@ -1584,6 +1584,8 @@ function _comment_per_page() {
       $num = base_convert((int) $i, 10, 36);
    
    @@ -1595,7 +1597,7 @@ function comment_int_to_alphadecimal($i = 0) {
       return base_convert(substr($c, 1), 36, 10);
    

    Shouldn't this just wrap the code in Comment?

dawehner’s picture

+++ b/core/modules/comment/lib/Drupal/comment/Entity/Comment.php
@@ -462,4 +462,21 @@ public static function preCreate(EntityStorageControllerInterface $storage_contr
+  function alphadecimalToInt($c = '00') {
+    return base_convert(substr($c, 1), 36, 10);
...
+
...
+  }

+++ b/core/modules/comment/lib/Drupal/comment/CommentInterface.php
@@ -35,4 +35,28 @@
+  public static function intToAlphadecimal($i = 0);
...
+  function alphadecimalToInt($c = '00');

Both are static methods which I think we really don't have to put into the interface.

andypost’s picture

Issue tags: +API clean-up
StatusFileSize
new3.41 KB
new5.96 KB

Added unit test, and fixed doc-blocks

@larowlan there's some specific substr() so not sure about 2.
@dawehner Probably but EntityInterface already exposes some static methods, so not sure

larowlan’s picture

+++ b/core/modules/comment/comment.module
@@ -1584,6 +1584,8 @@ function _comment_per_page() {
   $num = base_convert((int) $i, 10, 36);

@@ -1595,7 +1597,7 @@ function comment_int_to_alphadecimal($i = 0) {
   return base_convert(substr($c, 1), 36, 10);

Shouldn't the old functions just wrap the new ones?

andypost’s picture

Title: Deprecate comment_int_to_alphadecimal() & comment_alphadecimal_to_int() in favour of method on Comment entity » Deprecate comment_int_to_alphadecimal() & comment_alphadecimal_to_int() in favour of methods in Number component
Issue summary: View changes
StatusFileSize
new8.01 KB

This functions are really number specific so moved to proper component
Re-title, also fixed CommentLockTest.php test to expect real values

Status: Needs review » Needs work

The last submitted patch, 6: 2157703-comment-static-6.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

6: 2157703-comment-static-6.patch queued for re-testing.

larowlan’s picture

Not sure on the group name in the new test's getInfo method, should it be common instead of commons?
Other than that rtbc.

andypost’s picture

StatusFileSize
new602 bytes
new8.01 KB

Re-roll for Common

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

andypost’s picture

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Still need to sort out the @deprecated tag but there's an issue open for that.

Status: Fixed » Closed (fixed)

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

ianthomas_uk’s picture

Opened #2187653: Remove comment_alphadecimal_to_int and comment_int_to_alphadecimal to remove these, as they are unused and comment_int_to_alphadecimal doesn't do what it's meant to.