TypeError: explode(): Argument #2 ($string) must be of type string, array given in explode()

Created on 12 April 2024, 8 months ago
Updated 13 May 2024, 7 months ago

Problem/Motivation

When using the smart_date module, a TypeError was encountered in the SmartDateListItemBase class. If the parseValues() method receives an array instead of a string as an argument, it results in a TypeError due to an attempt to use the explode() function on an array.

Steps to reproduce

1. Update the smart_date module to version 4.1.0-rc6.
2. Perform an action that involves the parseValues() method. Create a new Entity (Content Type, Block, Paragraph..) with a smart_date field

Proposed resolution

It is proposed to modify the parseValues() method to check the data type of the $values variable before using explode(), converting the array to a string if necessary.

Remaining tasks

Review the proposed patch, test it, and if the solution is accepted, apply it to the module.

User interface changes

N/A.

API changes

N/A.

Data model changes

N/A.

🐛 Bug report
Status

Fixed

Version

4.1

Component

Code

Created by

🇦🇷Argentina pablo.fredes Rosario

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

Merge Requests

Comments & Activities

  • Issue created by @pablo.fredes
  • 🇦🇷Argentina pablo.fredes Rosario

    pablo.fredes changed the visibility of the branch 3440576-typeerror-explode-argument to hidden.

  • Pipeline finished with Canceled
    8 months ago
    Total: 106s
    #145327
  • Pipeline finished with Success
    8 months ago
    Total: 189s
    #145329
  • Pipeline finished with Success
    8 months ago
    Total: 183s
    #145333
  • 🇨🇦Canada mandclu

    In what version of Drupal was this observed?

  • 🇦🇷Argentina pablo.fredes Rosario

    Hello mandclu
    This is on Drupal version 10

  • 🇦🇷Argentina pablo.fredes Rosario

    Hello mandclu
    This is on Drupal version 10

  • Status changed to Postponed: needs info 8 months ago
  • 🇨🇦Canada mandclu

    Here's what I tried:

    On a site running Drupal 10.2, I created a new content type and added a Smart Date field. No error.

    I created a new node of the new type. No error.

    I'm going to need more detailed steps to reproduce your issue on a fresh install of Drupal.

  • 🇦🇹Austria ViNCE

    https://www.drupal.org/files/issues/2024-04-12/smart_date_type_string.patch --> worked for me.

    Before error message was:
    The website encountered an unexpected error. Try again later.

    TypeError: explode(): Argument #2 ($string) must be of type string, array given in explode() (line 30 of modules/contrib/smart_date/src/Plugin/Field/FieldType/SmartDateListItemBase.php).

    Drupal\smart_date\Plugin\Field\FieldType\SmartDateListItemBase::Drupal\smart_date\Plugin\Field\FieldType\{closure}() (Line: 40)
    Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall() (Line: 36)
    Drupal\smart_date\Plugin\Field\FieldType\SmartDateListItemBase::parseValues() (Line: 247)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::createWidget() (Line: 185)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement() (Line: 110)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateDefaultWidget->formElement() (Line: 35)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateInlineWidget->formElement() (Line: 40)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget->formElement() (Line: 459)
    Drupal\Core\Field\WidgetBase->formSingleElement() (Line: 550)
    Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formMultipleElements() (Line: 120)
    Drupal\Core\Field\WidgetBase->form() (Line: 186)
    Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm() (Line: 121)
    Drupal\Core\Entity\ContentEntityForm->form() (Line: 127)
    Drupal\node\NodeForm->form() (Line: 107)
    Drupal\Core\Entity\EntityForm->buildForm()
    call_user_func_array() (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 270)
    Drupal\shield\ShieldMiddleware->bypass() (Line: 178)
    Drupal\shield\ShieldMiddleware->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • Status changed to Fixed 8 months ago
  • 🇨🇦Canada mandclu

    I still have never been able to reproduce the error, but I updated to code to only run the explode if the $values aren't already an array, which seems like a sensible check anyway.

  • Pipeline finished with Skipped
    8 months ago
    #160109
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024