Problem/Motivation

When I tried to import date column it gives :

Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Feeds\Target\DateTargetBase->convertToDate() (line 26 of /modules/feeds/src/Feeds/Target/DateTargetBase.php)

#0 /core/includes/bootstrap.inc(347): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /modules/feeds/src/Feeds/Target/DateTargetBase.php(26): trim()
#3 /modules/feeds/src/Feeds/Target/DateTime.php(50): Drupal\feeds\Feeds\Target\DateTargetBase->convertToDate()
#4 /modules/feeds/src/Feeds/Target/DateTime.php(36): Drupal\feeds\Feeds\Target\DateTime->prepareDateValue()
#5 /modules/feeds/src/Plugin/Type/Target/FieldTargetBase.php(156): Drupal\feeds\Feeds\Target\DateTime->prepareValue()
#6 /modules/feeds/src/Plugin/Type/Target/FieldTargetBase.php(92): Drupal\feeds\Plugin\Type\Target\FieldTargetBase->prepareValues()
#7 /modules/feeds/src/Feeds/Processor/EntityProcessorBase.php(1092): Drupal\feeds\Plugin\Type\Target\FieldTargetBase->setTarget()
#8 /modules/feeds/src/Feeds/Processor/EntityProcessorBase.php(178): Drupal\feeds\Feeds\Processor\EntityProcessorBase->map()
#9 /modules/feeds/src/EventSubscriber/LazySubscriber.php(110): Drupal\feeds\Feeds\Processor\EntityProcessorBase->process()
#10 [internal function]: Drupal\feeds\EventSubscriber\LazySubscriber->Drupal\feeds\EventSubscriber\{closure}()
#11 /core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#12 /modules/feeds/src/Event/EventDispatcherTrait.php(38): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#13 /modules/feeds/src/FeedsExecutable.php(266): Drupal\feeds\FeedsExecutable->dispatchEvent()
#14 /modules/feeds/src/FeedsExecutable.php(113): Drupal\feeds\FeedsExecutable->doProcess()
#15 /core/includes/batch.inc(295): Drupal\feeds\FeedsExecutable->processItem()
#16 /core/includes/batch.inc(137): _batch_process()
#17 /core/includes/batch.inc(93): _batch_do()
#18 /core/modules/system/src/Controller/BatchController.php(55): _batch_page()
#19 [internal function]: Drupal\system\Controller\BatchController->batchPage()
#20 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#21 /core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#23 /core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#24 /vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 /vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#26 /core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#27 /core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#28 /core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#29 /core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#30 /core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#31 /core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#32 /vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#33 /core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle()
#34 /index.php(19): Drupal\Core\DrupalKernel->handle()
#35 {main}

-------- This issue is very similar to already reported one :"https://www.drupal.org/project/feeds/issues/3267244" However I cannot fix it ,so anyone can help to resolve that issue after upgrading to PHP 8.1.14

Issue fork feeds-3306211

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

coaston created an issue. See original summary.

coaston’s picture

Issue summary: View changes
coaston’s picture

Ok it seems I was successful :

* @return \Drupal\Core\Datetime\DrupalDateTime|null
* A datetime object or null, if there is no value or if the date value
* has errors.
*/
protected function convertToDate($value) {
- $value = trim($value);
+ $value = trim($value ?? '');

This change on (line 26 of /modules/feeds/src/Feeds/Target/DateTargetBase.php) fixed the issue. Anyone can double check and provide the patch ?

coaston’s picture

Status: Active » Needs review
megachriz’s picture

It would be good if this bug is covered by an automated test.

Can you provide the config file from your feed type + the source file you were trying to import?

You can export your configuration this way:

  1. Enable the Configuration Manager module (part of Drupal core).
  2. Go to Administration > Configuration > Development > Synchronize > Export > Single item (admin/config/development/configuration/single/export).
  3. Select a configuration type and name.
VenkatK’s picture

Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\feeds\Feeds\Target\Boolean->prepareValue() (line 24 modules/contrib/feeds/src/Feeds/Target/Boolean.php)

We have similar issue in Boolean.php

megachriz’s picture

@VenkatK
Alright, please share the source file and your feed type configuration. This way we can write an automated test for the bug.

coaston’s picture

Hi MegaChriz, will provide the config later next week due to vacation, but it seems it happens when there is date field in feeds but this column is missing in csv.

Example :

Feed config has 3 fields :
Title,
Date1
Date2

and this reported issue occures when you create csv with just 2 columns Title and Date1....so Date2 is missing and instead of ignoring it ,it will throw such error. However it seems this works fine when there is any other field type and it will just ignore such missing column with string for example.

But I will confirm next week.

solideogloria’s picture

Status: Needs review » Needs work

FYI: The null-coalesce operator ?? was introduced in PHP 7.0, so if you use that, you need to add php = 7.0 as a minimum version requirement in the feeds.info file.

coaston’s picture

Hi solideaoglori
My Php version is 8.1.4

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

lind101’s picture

Title: Deprecated function: trim(): » Deprecated function: trim(): Passing null is deprecated as of PHP 8
Status: Needs work » Needs review

There are a few places in the FieldTarget classes where trim and strlen function are being use without checking for the existance of a string value. This will create warning for people using PHP 8 or higher.

MR!90 is a first pass at suppressing these warnings for PHP 8 users and still making sure the module works for users running older versions of PHP.

Updated the issue title to include refernce to PHP 8.

coaston’s picture

Status: Needs review » Reviewed & tested by the community

Hi All,

I can confirm above merge #13 worked for me and resolved my reported issues, hence this can be closed and added to new release.

megachriz’s picture

Issue tags: +Needs tests
StatusFileSize
new1.1 KB
new16 bytes

It would still be useful to have automated tests for this.

I was able to reproduce the issue when mapping to a date field. I've attached a feed type to reproduce the issue with. And a CSV file.

  • MegaChriz committed 0f49a1c on 8.x-3.x authored by lind101
    Issue #3306211 by MegaChriz, lind101, coaston: Fixed PHP 8 deprecation:...
megachriz’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

Merged the code. Thanks all!

Status: Fixed » Closed (fixed)

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