SmartDate passes some default allowed values for durations as string, which is deprecated in Drupal 10.2 and throws a notice:

extractAllowedValues('60|1 hour\r\n', 1)
User deprecated function: Passing a string to Drupal\options\Plugin\Field\FieldType\ListItemBase::extractAllowedValues() is deprecated in drupal:10.2.0 and will cause an error from drupal:11.0.0. Use an array instead. See https://www.drupal.org/node/3376368 in Drupal\options\Plugin\Field\FieldType\ListItemBase::extractAllowedValues() (Zeile 406 in /app/web/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php)
#0 /app/web/core/includes/bootstrap.inc(164): _drupal_error_handler_real(16384, 'Passing a strin...', '/app/web/core/m...', 406)
#1 [internal function]: _drupal_error_handler(16384, 'Passing a strin...', '/app/web/core/m...', 406)
#2 /app/web/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php(406): trigger_error('Passing a strin...', 16384)
#3 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldType/SmartDateListItemBase.php(17): Drupal\options\Plugin\Field\FieldType\ListItemBase::extractAllowedValues('60|1 hour\r\n', 1)
#4 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php(245): Drupal\smart_date\Plugin\Field\FieldType\SmartDateListItemBase::parseValues('60|1 hour\r\n')
#5 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php(183): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::createWidget(Array, Array, Array)
#6 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateDefaultWidget.php(110): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#7 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateInlineWidget.php(35): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateDefaultWidget->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#8 /app/web/core/lib/Drupal/Core/Field/WidgetBase.php(448): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateInlineWidget->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#9 /app/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php(529): Drupal\Core\Field\WidgetBase->formSingleElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#10 /app/web/core/lib/Drupal/Core/Field/WidgetBase.php(117): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formMultipleElements(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), Array, Object(Drupal\Core\Form\FormState))
CommentFileSizeAuthor
#2 3409287.patch743 bytessidharth_soman

Issue fork smart_date-3409287

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

drubb created an issue. See original summary.

sidharth_soman’s picture

StatusFileSize
new743 bytes

Apply this patch and it should remove the deprecation error. Please test.

sassafrass’s picture

Thank-you! Patch worked for me!

tderego’s picture

Yes. Patch works for me. Smart Date 4.0.3, Drupal 10.2.0.

johnlutz’s picture

Patch works for me. Drupal 10.2.0. Smart Date 4.0.3

josh.fabean’s picture

Also tested patch and removes the error for me.

rolodmonkey’s picture

Status: Active » Needs review
rolodmonkey’s picture

Is the 4.1 branch set up for automated testing? If so, the patch needs to be submitted in the correct way so that it will trigger automated testing.

rolodmonkey’s picture

I have applied this patch while running Drupal 10.2.0 and it works.

scotwith1t’s picture

Working for me as well. Hope to see this passing tests and RTBC soon :) Thanks!

transmitter’s picture

#2 seems to be working fine here as well.
Thanks.

krug’s picture

#2 works for me. Drupal 10.2.2 Smart Date 4.0.3 Thanks.

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

pcate’s picture

I made a MR of patch #2 for convenience.

mowgli4811’s picture

#2 worked for me. Drupal 10.2.3 Smart Date 4.0.3

mortona2k’s picture

Status: Needs review » Reviewed & tested by the community

Patch fixes issues in 4.1.0 as well.

The $values comes from the field settings form, it's a handcoded text area with an option on each line.

This patch does an explode on the values string to get a list. Then trims the lines and filters out empty values.

Looks good to me, my only concern is whether we're doing enough checking, but if the values are entered correctly this is working great.

heddn’s picture

+1 on RTBC.

ransomweaver’s picture

RTBC looks good.

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

mandclu’s picture

The unfortunate part of the change proposed is that it isn't backwards-compatible with versions of Drupal before 10.2 As such, I've added a commit to make Smart Date require Drupal 10.2 or newer.

Having core throw the deprecation warning everywhere a Smart Date widget is used is extremely annoying, but it feels very early to start requiring Drupal 10.2. Unfortunately this is probably something we're going to need to patch for a while.

The only other way I could see resolving this would be to remove the use of ListItemBase::extractAllowedValues() altogether and duplicate the logic within SmartDateListItemBase::parseValues() but I'd still prefer to stay aligned with how core handles the same kind of input.

anand.panure’s picture

After upgrading the module to 4.0 and applying this patch https://www.drupal.org/files/issues/2023-12-18/3409287.patch, my dbupdate command is failing to update the hook views_post_update_timestamp_formatter and I saw this module does implement that hook.
I am on Drupal 10.2.3.

Error Log below -

>  [notice] Update started: views_post_update_timestamp_formatter
>  [error]  Error: Call to a member function getType() on null in Drupal\views\Plugin\views\field\EntityField->defineOptions() (line 375 of /var/www/html/docroot/core/modules/views/src/Plugin/views/field/EntityField.php) #0 /var/www/html/docroot/core/modules/views/src/Plugin/views/PluginBase.php(143): Drupal\views\Plugin\views\field\EntityField->defineOptions()
> #1 /var/www/html/docroot/core/modules/views/src/Plugin/views/HandlerBase.php(109): Drupal\views\Plugin\views\PluginBase->init()
> #2 /var/www/html/docroot/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(136): Drupal\views\Plugin\views\HandlerBase->init()
> #3 /var/www/html/docroot/core/modules/views/src/Plugin/views/field/EntityField.php(199): Drupal\views\Plugin\views\field\FieldPluginBase->init()
> #4 /var/www/html/docroot/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(899): Drupal\views\Plugin\views\field\EntityField->init()
> #5 /var/www/html/docroot/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(927): Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers()
> #6 /var/www/html/docroot/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(963): Drupal\views\Plugin\views\display\DisplayPluginBase->getAllHandlers()
> #7 /var/www/html/docroot/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(71): Drupal\views\Plugin\views\display\DisplayPluginBase->calculateDependencies()
> #8 /var/www/html/docroot/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(89): Drupal\Core\Config\Entity\ConfigEntityBase->getPluginDependencies()
> #9 /var/www/html/docroot/core/modules/views/src/Entity/View.php(283): Drupal\Core\Config\Entity\ConfigEntityBase->calculatePluginDependencies()
> #10 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(321): Drupal\views\Entity\View->calculateDependencies()
> #11 /var/www/html/docroot/core/modules/views/src/Entity/View.php(293): Drupal\Core\Config\Entity\ConfigEntityBase->preSave()
> #12 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\views\Entity\View->preSave()
> #13 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\EntityStorageBase->doPreSave()
> #14 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(257): Drupal\Core\Entity\EntityStorageBase->save()
> #15 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(352): Drupal\Core\Config\Entity\ConfigEntityStorage->save()
> #16 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(609): Drupal\Core\Entity\EntityBase->save()
> #17 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityUpdater.php(192): Drupal\Core\Config\Entity\ConfigEntityBase->save()
> #18 /var/www/html/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityUpdater.php(147): Drupal\Core\Config\Entity\ConfigEntityUpdater->doOne()
> #19 /var/www/html/docroot/core/modules/views/views.post_update.php(82): Drupal\Core\Config\Entity\ConfigEntityUpdater->update()
> #20 /var/www/html/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(280): views_post_update_timestamp_formatter()
> #21 [internal function]: Drush\Commands\core\UpdateDBCommands::updateDoOnePostUpdate()
> #22 /var/www/html/vendor/drush/drush/includes/batch.inc(257): call_user_func_array()
> #23 /var/www/html/vendor/drush/drush/includes/batch.inc(204): _drush_batch_worker()
> #24 /var/www/html/vendor/drush/drush/includes/batch.inc(75): _drush_batch_command()
> #25 /var/www/html/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(136): drush_batch_command()
> #26 [internal function]: Drush\Commands\core\UpdateDBCommands->process()
> #27 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
> #28 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
> #29 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
> #30 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process()
> #31 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
> #32 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run()
> #33 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
> #34 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
> #35 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
> #36 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
> #37 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run()
> #38 /var/www/html/vendor/drush/drush/drush(4): require('...')
> #39 /var/www/html/vendor/bin/drush(120): include('...')
> #40 {main}. 
>  [warning] Drush command terminated abnormally.

In ProcessBase.php line 171:
                                                                                                                            
  Unable to decode output into JSON: Syntax error                                                                           
                                                                                                                            
  Error: Call to a member function getType() on null in Drupal\views\Plugin\views\field\EntityField->defineOptions() (line  
   375 of /var/www/html/docroot/core/modules/views/src/Plugin/views/field/EntityField.php).                                 
                                                                                         
daisyleroy’s picture

#2 works for me !

mglaman’s picture

Assigned: Unassigned » mglaman
Status: Reviewed & tested by the community » Needs work

This can use the be backwards compatibility call to support previous versions. See https://www.drupal.org/node/3379306

Assigning to myself and picking this up.

mglaman’s picture

Assigned: mglaman » Unassigned
Status: Needs work » Needs review

Updated the MR.

If DeprecationHelper doesn't exist, use the deprecated code path for Drupal 9, etc.
If DeprecationHelper exists, allows the deprecated code path and new code path for all Drupal 10 and beyond versions

mglaman’s picture

Issue tags: +MidCamp 2024

  • mandclu committed 1dcd8f2b on 4.1.x authored by PCate
    Issue #3409287 by mglaman, mandclu, sidharth_soman: Deprecation in...
mandclu’s picture

Status: Needs review » Fixed

I was able to verify that the merge request removes the deprecation warning in Drupal 10, but allows the module to still work as intended with older versions of Drupal. Merged in, and will incorporate into a new release shortly. Thanks @mglaman!

Status: Fixed » Closed (fixed)

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