- Issue created by @jurgenhaas
- Status changed to Needs review
almost 2 years ago 9:21am 28 February 2023 - π©πͺGermany jurgenhaas Gottmadingen
Also removed the return value in the constructor.
- @jurgenhaas opened merge request.
- π©πͺGermany jurgenhaas Gottmadingen
Updated the MR because the opacity can also be NULL and in PHP 8.1 that needs to be declared accordingly.
- πΊπ¦Ukraine itaran
Thanks for the proposed solution and PR, hopefully these will be accepted soon. Run into the same problem with php 8.1, attaching quick fix patch with casting $item->opacity to string value.
- Status changed to RTBC
almost 2 years ago 3:01pm 15 March 2023 - π΅πPhilippines clarkssquared
Hi jurgenhaas,
I confirmed the issue was resolved when I applied patch #5 to the "Color Field" against Version
3.0.x-dev. Please look at the screenshots attached.For your review.
Thank you. - π΅π±Poland bronismateusz
I applied this patch, but when setting the field formatting to Color CSS declaration and trying to save the settings with layout_builder enabled, the error still occurs.
The last submitted patch, 8: color_field-opacity_wrong_type-3344907-8.patch, failed testing. View results β
- π΅π±Poland bronismateusz
I forgot modified also `ColorFieldFormatterCss.php` file. Now should be okay in layout_builder display and on page.
- Status changed to Needs work
over 1 year ago 10:11pm 26 April 2023 I was a little hasty in marking as RTBC and didn't test sufficiently. Seems like when loading the entity to be viewed, the opacity value returned from DB is a string, so there are errors with the formatters:
The website encountered an unexpected error. Please try again later. TypeError: Drupal\color_field\ColorHex::__construct(): Argument #2 ($opacity) must be of type ?float, string given, called in /var/www/html/web/modules/contrib/color_field/src/Plugin/Field/FieldFormatter/ColorFieldFormatterText.php on line 131 in Drupal\color_field\ColorHex->__construct() (line 30 of modules/contrib/color_field/src/ColorHex.php). Drupal\color_field\ColorHex->__construct('#EC1818', '0.7') (Line: 131) Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterText->viewValue(Object) (Line: 81)
- last update
over 1 year ago Composer require failure - Status changed to Needs review
over 1 year ago 5:36pm 27 April 2023 OK, so it looks like, depending on context, the opacity value passed to the ColorHex constructor can be NULL, float/int, or string.
- When loading opacity value from DB to view in formatter, value is string
- When editing a paragraph with color field in Layout Paragraphs builder, the opacity will be a float
- When editing default layout of content type with a color field, opacity can be a int
One simple way would be to use a union type hint of
?string|float
, but that is PHP 8+ only.I wonder if there's a core issue to cast values to float when retrieved from DB storage for fields of type float (or similarly for any other fields).
Anyway, for now:
Pushed a commit to the MR to cast opacity to the right value before passing into Constructor in the formatters and in the module file.- Status changed to RTBC
over 1 year ago 11:06am 29 June 2023 - π©πͺGermany jurgenhaas Gottmadingen
@godotislate your latest commit to the MR looks great and should solve all possible issues.
- π¨π¦Canada simgui8 Canada
MR looks good and fixes the issue for me.
Thanks
- last update
over 1 year ago 9 pass - π§π·Brazil rafmagsou
Patch #9 updated to Drupal 10 context, apply the same guarantee to #1 parameter.
- last update
over 1 year ago Composer require failure - last update
over 1 year ago 9 pass - π§π·Brazil rafmagsou
Generate a patch with the solution proposed on the merge request Compatible with D10 php 8.1
- last update
over 1 year ago Composer require failure - π³π±Netherlands MLZR Zutphen
patch #17 is working for me too - thanks!
-
mandclu β
committed 1c234e3e on 3.0.x
Issue #3344907 by rafmagsou, jurgenhaas, bronisMateusz, godotislate,...
-
mandclu β
committed 1c234e3e on 3.0.x
- Status changed to Fixed
7 months ago 5:06pm 3 June 2024 Automatically closed - issue fixed for 2 weeks with no activity.