Problem/Motivation

When creating a new node and on that node you have an AJAX submit for example when inserting media from the media library you will receive some deprecation warnings.

In PathAutoState.php

/**
   * Gets the data value currently stored in database.
   *
   * @return mixed
   *   The data value.
   */
  protected function getOriginalValue() {
    if ($this->originalValue === NULL) {
      // If no value has been set or loaded yet, try to load a value if this
      // entity has already been saved.
     $this->originalValue = \Drupal::keyValue($this->getCollection())
        ->get(static::getPathautoStateKey($this->parent->getEntity()->id()));
    }

    return $this->originalValue;
  }

this function will pass NULL because the entity is new.
Thus in my patch I will stop it here/fix it here.

Nonetheless the warnings come from here:

  public static function getPathautoStateKey($entity_id) {
    $entity_id_is_ascii = mb_check_encoding($entity_id, 'ASCII');
    if ($entity_id_is_ascii && strlen($entity_id) <= 128) {
      // The original entity ID, if it's an ASCII of 128 characters or less.
      return $entity_id;
    }
    return Crypt::hashBase64($entity_id);
  }

Question?: Should we add an extra check in here?

Remaining tasks

Review + Answer question

Issue fork pathauto-3268094

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Mschudders created an issue. See original summary.

Berdir made their first commit to this issue’s fork.

  • Berdir committed 14f5af1 on 8.x-1.x
    Issue #3268094 by Mschudders: PHP 8.1 deprecated functions + General fix
    
berdir’s picture

Status: Needs review » Fixed

I'd say the fix is fine, the function does not support passing in NULL. I'd say once we require PHP 8 we could add a int|string type definition there and then it will fail earlier, but for now, this is good enough. Merged.

Status: Fixed » Closed (fixed)

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