Hello,

After updated my Pathauto module to 8.x-1.2, I get this message when I want to create a new content:


Error message

   <strong> Deprecated function: mb_check_encoding(): Calling mb_check_encoding() without argument is deprecated in Drupal\pathauto\PathautoState::getPathautoStateKey() (line 182 of modules/contrib/pathauto/src/PathautoState.php).</strong>

    Drupal\pathauto\PathautoState::getPathautoStateKey(NULL) (Line: 45)
    Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
    count(Object) (Line: 74)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
    Drupal\node\NodeForm->form(Array, Object) (Line: 106)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('node_article_block_cta_form', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    <strong>Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\pathauto\PathautoState::getPathautoStateKey() (line 183 of modules/contrib/pathauto/src/PathautoState.php).
</strong>
    Drupal\pathauto\PathautoState::getPathautoStateKey(NULL) (Line: 45)
    Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
    count(Object) (Line: 74)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
    Drupal\node\NodeForm->form(Array, Object) (Line: 106)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('node_article_block_cta_form', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Issue fork pathauto-3394550

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

lorseau created an issue. See original summary.

abhishek_gupta1’s picture

Assigned: Unassigned » abhishek_gupta1
shreya_th’s picture

Assigned: Unassigned » shreya_th
shreya_th’s picture

Assigned: shreya_th » Unassigned
abhishek_gupta1’s picture

Assigned: Unassigned » abhishek_gupta1

abhishek_gupta1’s picture

Assigned: abhishek_gupta1 » Unassigned
Status: Active » Needs review

@lorseau, I have fix the issue Deprecated function: mb_check_encoding(), please kindly review the Patch file

abhishek_gupta1’s picture

StatusFileSize
new876 bytes

Status: Needs review » Needs work

The last submitted patch, 8: pathauto-3394550.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

roshni27’s picture

Status: Needs work » Needs review
StatusFileSize
new712 bytes

Please review the patch.

lorseau’s picture

Hello,

I checked the 3394550-10.patch and now I get these errors:

Error message

    Warning: Undefined variable $entity_id_is_ascii in Drupal\pathauto\PathautoState::getPathautoStateKey() (line 185 of modules/contrib/pathauto/src/PathautoState.php).

    Drupal\pathauto\PathautoState::getPathautoStateKey(NULL) (Line: 45)
    Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
    count(Object) (Line: 74)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
    Drupal\node\NodeForm->form(Array, Object) (Line: 106)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('node_article_career_form', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    Deprecated function: hash(): Passing null to parameter #2 ($data) of type string is deprecated in Drupal\Component\Utility\Crypt::hashBase64() (line 49 of core/lib/Drupal/Component/Utility/Crypt.php).

    Drupal\Component\Utility\Crypt::hashBase64(NULL) (Line: 189)
    Drupal\pathauto\PathautoState::getPathautoStateKey(NULL) (Line: 45)
    Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
    Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
    count(Object) (Line: 74)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
    Drupal\node\NodeForm->form(Array, Object) (Line: 106)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('node_article_career_form', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

lorseau’s picture

@abhishek_virasat, looks like the patch failed
and there is the mb_check_encoding() error but also the strlen() error too

abhishek_gupta1’s picture

@lorseau, you mean to say, you applied the "pathauto-3394550.patch" but still you got same error and also for strlen() ? or you not able to apply ?

lorseau’s picture

@abhishek_virasat, I didn't applied your patch as it failed

The last submitted patch, 8: pathauto-3394550.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

roshni27’s picture

StatusFileSize
new771 bytes

Updated patch please review.

lorseau’s picture

thanks @roshni27

I still have the second error:

Error message
Deprecated function: hash(): Passing null to parameter #2 ($data) of type string is deprecated in Drupal\Component\Utility\Crypt::hashBase64() (line 49 of core/lib/Drupal/Component/Utility/Crypt.php).

Drupal\Component\Utility\Crypt::hashBase64(NULL) (Line: 190)
Drupal\pathauto\PathautoState::getPathautoStateKey(NULL) (Line: 45)
Drupal\pathauto\PathautoFieldItemList->computeValue() (Line: 34)
Drupal\path\Plugin\Field\FieldType\PathFieldItemList->ensureComputedValue() (Line: 141)
Drupal\path\Plugin\Field\FieldType\PathFieldItemList->count()
count(Object) (Line: 74)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 183)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
Drupal\node\NodeForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('node_article_blog_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

roshni27’s picture

StatusFileSize
new1.06 KB

This code should handle various cases, including when entity_id is null or not a valid string.

Status: Needs review » Needs work

The last submitted patch, 18: 3394550-18.patch, failed testing. View results

berdir’s picture

The caller of getPathautoStateKey() should ensure that it's a string, and I thought we already do that.

lorseau’s picture

@roshni27, 3394550-18.patch works for me
thanks

roshni27’s picture

@Berdir Please suggest me what logic we should implement here when $entity_id is null?

berdir’s picture

Investigate the backtrace where this error happens and don't call this method then. We already have an isNew() check in \Drupal\pathauto\PathautoState::getOriginalValue() for example.

The backtrace in #17 suggests to me that @lorseau is *not* using the most recent version or is using patches because those line numbers are different to where I'm seeing calls.

lorseau’s picture

Status: Needs work » Needs review

@Berdir

I have the latest version, but I also have these patches:

"Issue #3179835: Migrate forum pattern to taxonomy term forums if forum is enabled on the source site": "https://www.drupal.org/files/issues/2022-01-06/pathauto-migrate_forum_pa...",

"Issue #3179865: Derive pathauto pattern migrations to solve inaccurate pattern migration dependencies": "https://www.drupal.org/files/issues/2021-04-06/pathauto-derive_pathauto_...",

"Issue #3182708: Migrate language-specific patterns": "https://www.drupal.org/files/issues/2022-01-06/pathauto-migrate_multilin...",

"Issue #3079275: Custom aliases (which are not generated with the actual patterns) can be lost during the migration": "https://www.drupal.org/files/issues/2022-01-06/pathauto-prevent_losing_c...",

"Issue #3190980: [PP-1] Allow source counts to be cached: implement ::doCount() instead of ::count()": "https://www.drupal.org/files/issues/2021-01-05/3190980-2.patch",

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

chrisdarke’s picture

@Berdir, the issue that I was able to replicate with 8.x-1.x was that PathautoFieldItemList::computeValue() was getting a null value from $this->getEntity()->id(), which can happen.. unless I misunderstand there can be cases where enforceIsNew is set but id is null.
I added an updated MR that successfully installs and fixes the issue on my local instance.

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

mably’s picture

Code review

The commit correctly addresses the issue. When creating a new entity (before save), $entity->id() returns NULL. This NULL gets passed to getPathautoStateKey() which calls mb_check_encoding(NULL, 'ASCII') and strlen(NULL) — both deprecated since PHP 8.1.

The fix adds an early return if ($entity_id === NULL) return NULL; which prevents the deprecation warnings. The return type is correctly updated to int|string|null.

Downstream safety

The main caller that triggers this with NULL is getOriginalValue() at line 75:

->get(static::getPathautoStateKey($this->parent->getEntity()->id()));

It already has an isNew() guard, but there are edge cases where isNew() returns FALSE while id() is still NULL (e.g. entity cloning). I've added an additional || $entity->id() === NULL guard in getOriginalValue() so NULL never reaches the key-value store's get() method either — which would otherwise violate its string type hint.

The other callers (persist() at line 109 and purge() at line 117) only run on saved entities so they won't receive NULL.

mably’s picture

Added a kernel test testUnsavedEntityPathFieldAccess() that reproduces the bug by creating a node without saving it and accessing its path field. A custom error handler captures any deprecation warnings, then the test asserts that no mb_check_encoding() or strlen() deprecations were triggered. It also verifies that PathautoState::getPathautoStateKey(NULL) returns NULL gracefully. Verified that the test fails without the fix and passes with it.

mably changed the visibility of the branch 3394550-deprecated-function-mbcheckencoding to hidden.

mably’s picture

Assigned: Unassigned » berdir
berdir’s picture

Status: Needs review » Closed (outdated)

Per my review comment, the test does not fail for me on $node->path->pathauto.

> unless I misunderstand there can be cases where enforceIsNew() is set but id is null.

there was in fact a a core bug a while ago that I fixed that allowed this, you could force a new entity to be not new, and then this would trigger this case. But that bug has been fixed in core, isNew() will _never_ return FALSE now if the entity has no ID. That did happen sometime between 2023 and now. So it is possible that some edge case triggered this back then, but that is no longer happening on supported core versions.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.