Deprecation in Drupal 10.2: Smart Date List Item allowed values must be passed as array

Created on 17 December 2023, 11 months ago
Updated 6 April 2024, 8 months ago

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))
📌 Task
Status

Fixed

Version

4.1

Component

Code

Created by

🇩🇪Germany drubb Sindelfingen

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

Merge Requests

Comments & Activities

  • Issue created by @drubb
  • 🇮🇳India sidharth_soman Bangalore

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

  • 🇺🇸United States sassafrass

    Thank-you! Patch worked for me!

  • 🇺🇸United States tderego Starkville, MS

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

  • 🇺🇸United States johnlutz

    Patch works for me. Drupal 10.2.0. Smart Date 4.0.3

  • 🇺🇸United States josh.fabean Florida

    Also tested patch and removes the error for me.

  • Status changed to Needs review 11 months ago
  • 🇺🇸United States RoloDMonkey

    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.

  • 🇺🇸United States RoloDMonkey

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

  • 🇺🇸United States scotwith1t Birmingham, AL

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

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

  • 🇷🇸Serbia krug

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

  • First commit to issue fork.
  • 🇺🇸United States pcate

    I made a MR of patch #2 for convenience.

  • 🇧🇪Belgium mowgli4811

    #2 didn't work for me. Composer couldn't apply the patch. Drupal 10.2.3 Smart Date 4.0.3

  • Status changed to RTBC 9 months ago
  • 🇺🇸United States mortona2k Seattle

    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.

  • 🇺🇸United States ransomweaver

    RTBC looks good.

  • First commit to issue fork.
  • 🇨🇦Canada mandclu

    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.

  • 🇺🇸United States anand.panure

    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).                                 
                                                                                             
  • Assigned to mglaman
  • Status changed to Needs work 8 months ago
  • 🇺🇸United States mglaman WI, USA

    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.

  • Issue was unassigned.
  • Status changed to Needs review 8 months ago
  • 🇺🇸United States mglaman WI, USA

    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

  • 🇺🇸United States mglaman WI, USA
  • Pipeline finished with Skipped
    8 months ago
    #127049
  • Status changed to Fixed 8 months ago
  • 🇨🇦Canada mandclu

    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!

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

Production build 0.71.5 2024