TypeError: Drupal\color_field\ColorHex::__construct(): Argument #2 ($opacity) must be of type ?string, int given

Created on 28 February 2023, almost 2 years ago
Updated 17 June 2024, 6 months ago

Problem/Motivation

We get the following exception when opening layout builder with a contained color field:

TypeError: Drupal\color_field\ColorHex::__construct(): Argument #2 ($opacity) must be of type ?string, int given, called in /var/www/html/web/modules/contrib/color_field/src/Plugin/Field/FieldFormatter/ColorFieldFormatterCss.php on line 312 in Drupal\color_field\ColorHex->__construct() (line 30 of modules/contrib/color_field/src/ColorHex.php).

Drupal\color_field\ColorHex->__construct() (Line: 312)
Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterCss->viewValue() (Line: 230)
Drupal\color_field\Plugin\Field\FieldFormatter\ColorFieldFormatterCss->viewElements() (Line: 89)
Drupal\Core\Field\FormatterBase->view() (Line: 265)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple() (Line: 266)
Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->buildMultiple() (Line: 223)
Drupal\Core\Entity\Entity\EntityViewDisplay->build() (Line: 461)
Drupal\Core\Entity\EntityViewBuilder->viewField() (Line: 243)
Drupal\Core\Field\FieldItemList->view() (Line: 162)
Drupal\layout_builder\Plugin\Block\FieldBlock->build() (Line: 106)
Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray->onBuildRender()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 90)
Drupal\layout_builder\SectionComponent->toRenderArray() (Line: 88)
Drupal\layout_builder\Section->toRenderArray() (Line: 242)
Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection() (Line: 126)
Drupal\layout_builder\Element\LayoutBuilder->layout() (Line: 100)
Drupal\layout_builder\Element\LayoutBuilder->preRender()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 788)
Drupal\Core\Render\Renderer->doCallback() (Line: 374)
Drupal\Core\Render\Renderer->doRender() (Line: 446)
Drupal\Core\Render\Renderer->doRender() (Line: 204)
Drupal\Core\Render\Renderer->render() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 50)
Drupal\ban\BanMiddleware->handle() (Line: 82)
Drupal\crowdsec\Middleware->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 713)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

All other ColorXYZ classes declare opacity as a float, only ColorHex uses string or NULL. This should be updated to float too.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

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

Comments & Activities

Production build 0.71.5 2024