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.

CommentFileSizeAuthor
smart_date_type_string.patch688 bytespablo.fredes

Issue fork smart_date-3440576

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

pablo.fredes created an issue. See original summary.

pablo.fredes’s picture

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

pablo.fredes’s picture

Issue summary: View changes
pablo.fredes’s picture

mandclu’s picture

In what version of Drupal was this observed?

pablo.fredes’s picture

Hello mandclu
This is on Drupal version 10

pablo.fredes’s picture

.

mandclu’s picture

Status: Active » Postponed (maintainer needs more info)

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.

vince’s picture

Same issue here.

Drupal Version: 10.2.5
Smart Date: 4.1.1

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

Before the full 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)

mandclu’s picture

Status: Postponed (maintainer needs more info) » Fixed

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.

  • mandclu committed 8ddbc2ff on 4.1.x authored by pablo.fredes
    Issue #3440576 by pablo.fredes, mandclu: TypeError: explode(): Argument...

Status: Fixed » Closed (fixed)

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