Deprecated function: mb_check_encoding(): Calling mb_check_encoding() without argument is deprecated in Drupal\pathauto

Created on 17 October 2023, about 1 year ago
Updated 23 October 2023, about 1 year ago

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)
🐛 Bug report
Status

Needs review

Version

1.12

Component

Code

Created by

🇫🇷France lorseau

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lorseau
  • Assigned to abhishek_virasat
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    3 pass, 22 fail
  • @abhishek_virasat opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India abhishek_virasat

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

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    3 pass, 22 fail
  • The last submitted patch, 8: pathauto-3394550.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • 🇮🇳India roshni27

    Please review the patch.

  • 🇫🇷France lorseau

    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)
    
    
  • 🇫🇷France lorseau

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

  • 🇮🇳India abhishek_virasat

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

  • 🇫🇷France lorseau

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

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    3 pass, 22 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    3 pass, 22 fail
  • The last submitted patch, 8: pathauto-3394550.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • 🇮🇳India roshni27

    Updated patch please review.

  • 🇫🇷France lorseau

    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)
    
    
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    42 pass, 2 fail
  • 🇮🇳India roshni27

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

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

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

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    42 pass, 2 fail
  • 🇫🇷France lorseau

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

  • 🇮🇳India roshni27

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

  • 🇨🇭Switzerland berdir Switzerland

    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.

  • Status changed to Needs review about 1 year ago
  • 🇫🇷France lorseau

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

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    48 pass
  • @chrisdarke opened merge request.
  • 🇬🇧United Kingdom ChrisDarke London

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

Production build 0.71.5 2024