strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\colorapi\Plugin\DataType\HexColorData::setValue()

Created on 16 February 2023, almost 2 years ago

Problem/Motivation

Whenever trying to create a new entity wherever the Color API field is used, it throws the following PHP error:
Deprecated function: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\colorapi\Plugin\DataType\HexColorData->setValue() (line 26 of modules/contrib/colorapi/src/Plugin/DataType/HexColorData.php).
Drupal\colorapi\Plugin\DataType\HexColorData->setValue(NULL, ) (Line: 140)
Drupal\Core\TypedData\TypedData->applyDefaultValue() (Line: 242)
Drupal\Core\TypedData\Plugin\DataType\Map->applyDefaultValue() (Line: 242)
Drupal\Core\TypedData\Plugin\DataType\Map->applyDefaultValue() (Line: 178)
Drupal\Core\Field\FieldItemList->applyDefaultValue() (Line: 274)
Drupal\Core\Entity\ContentEntityStorageBase->initFieldValues(Object, Array) (Line: 129)
Drupal\Core\Entity\ContentEntityStorageBase->doCreate(Array) (Line: 94)
Drupal\Core\Entity\ContentEntityStorageBase->create(Array) (Line: 370)
Drupal\Core\Entity\EntityForm->getEntityFromRouteMatch(Object, 'node') (Line: 73)
Drupal\Core\Entity\HtmlEntityFormController->getFormObject(Object, 'node.default.default') (Line: 58)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 159)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

This error only occurs if you are running Drupal on PHP Version >= 8.1

  1. Install Drupal 9
  2. Install the Color API module and configure it.
  3. Create a new Color field inside any content type.
  4. Goto Create new content of that content type

Proposed resolution

Check if the field value is empty before passing it to strupper() function in the setValue method of the HexColorData.php file. Submitting the patch for the same.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇳India rahul.rahangdale Pune

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024