Adding Color Field within a Custom Form for Layout Builder

Created on 11 June 2019, about 6 years ago
Updated 30 May 2025, 3 months ago

Hello,

I am trying to add in a Color Field to display the Widget Boxes and while looking through the code, I just cannot get it to display. Here is my code that I have that I'm trying to add the field for:

$form['bg_colors'] = [
              #type' => 'color_field_type',
              #title' => $this->t('Background Colors'),
              #default_value' => $this->configuration['bg_colors'],
              #description' => $this->t('Choose a background color for the whole layout.'),
            ];

But this doesn't render or show anything. If I change the '#type' variable to 'color', I get an HTML5 Color select box, but that will not work for me, as I need to limit the selection of colors to some very specific colors.

How can I implement the Color Field programmatically?

πŸ’¬ Support request
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ACoolDevDude California

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024