Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Color Picker Bundle Laravel Package

kunicmarko/color-picker-bundle

A small Symfony bundle that adds a color picker form type to Symfony forms, making it easy to render color input fields with minimal setup. Lightweight and simple to integrate, but with very low adoption and few stars, so check maintenance and compatibility before relying on it.

View on GitHub
Deep Wiki
Context7

Getting Started

This bundle gives Symfony's Form component a color-picker field type — essentially an HTML5 <input type="color"> wrapped in a reusable form type, with a themed Twig block so you can drop it into any form.

Minimal setup (it targets Symfony 3.x/4.x, pre-Flex and Flex era):

composer require kunicmarko/color-picker-bundle

Enable the bundle:

  • Symfony 3.x / 4.0 (AppKernel): add new KunicMarko\ColorPickerBundle\KunicMarkoColorPickerBundle() (check the README for the exact FQCN — the repo is small and the bundle class name is the one thing you cannot guess from the package name) to registerBundles().
  • Symfony 4.x with Flex: append it to config/bundles.php.

Then use it in a form — this is the whole first use case:

use KunicMarko\ColorPickerBundle\Form\Type\ColorType;

$builder->add('themeColor', ColorType::class);

Look first at the package README (it is short) and the Resources/views/Form directory for the Twig block, then at Form/Type/ColorType.php to confirm the class name and any options it exposes. Since the bundle is archived (last release Dec 2017, 0 dependents), treat the source as the documentation of record rather than expecting updated docs.

Implementation Patterns

Entity storage. The field submits a hex string (#rrggbb) from the browser. Store it as a string column:

/**
 * @ORM\Column(type="string", length=7, nullable=true)
 */
private $themeColor;

Validation belongs to you, not the bundle. The bundle only renders and hydrates a string, so add a constraint so bots/curl requests can't write garbage:

use Symfony\Component\Validator\Constraints as Assert;

/**
 * @Assert\Regex(pattern="/^#[0-9a-fA-F]{6}$/", message="Enter a hex color.")
 */
private $themeColor;

Reusable type wrapper. For a domain-specific field, extend or compose rather than repeating options across forms:

class ThemeColorType extends AbstractType
{
    public function getParent(): string
    {
        return ColorType::class;
    }
}

Then $builder->add('themeColor', ThemeColorType::class) everywhere.

Rendering. In Twig, standard form rendering works once the bundle's form theme is active:

{{ form_row(form.themeColor) }}

If the widget doesn't render as a color swatch, the bundle's theme block isn't loaded — see Gotchas.

Default fallback. HTML5 color inputs cannot be empty in most browsers — an empty value defaults to #000000. If an unset color is meaningful, either show a separate "no color" checkbox or make the field required => false and normalize ''/null in a form event:

$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $e) {
    $data = $e->getData();
    if ($data === '') { $e->setData(null); }
});

Integration tips. Use it anywhere you already use Symfony forms — admin panels (Sonata/EasyAdmin), settings pages, tag/category color coding. Because it is just a form type, it composes with CollectionType, RepeatedType (for "confirm color"), and ChoiceType-driven defaults without extra glue.

Gotchas and Tips

  • It is archived. No security patches, no Symfony 5/6/7 support guarantee. On a modern codebase, replace it with a five-line custom type (getParent(): TextType::class, getBlockPrefix() returning a block that renders type="color"). The bundle buys you almost nothing you can't write yourself, and you keep control of compatibility.
  • Browser value format. HTML5 color inputs always submit lowercase 7-character hex (#a1b2c3). Don't assume uppercase or short hex (#fff); normalize on save if your downstream code expects a specific format.
  • No server-side validation and no JS picker. The "picker" is whatever the OS/browser provides — Safari and older browsers historically rendered a text field instead of a swatch. Mobile behavior varies. If you need a consistent cross-browser widget, you'll need to layer your own JS library, at which point the form type is redundant.
  • Form theme activation. If you use a custom form theme, the bundle's block won't be inherited automatically. Register it explicitly in twig.yaml:
    twig:
        form_themes:
            - '@KunicMarkoColorPicker/Form/fields.html.twig'
    
    (Verify the exact path in Resources/views.) A symptom of a missing theme is a plain <input type="text"> instead of a color swatch.
  • Debugging. bin/console debug:form App\Form\YourType lists registered types and their parents — use it to confirm the bundle's type is actually registered and to see which parent it delegates to. If the type isn't found, the bundle wasn't enabled.
  • Extension points are thin. The realistic extension points are (a) subclassing/getParent() to preset options, (b) overriding the Twig block to add attributes or a JS data-attribute hook, and (c) a FormTypeExtension if you want to apply the color widget globally to matching fields. There is no configuration tree worth configuring.
  • Dependency hygiene. Last release 2017 means its composer.json constraints likely pin to symfony/form ^3|^4. On Symfony 5+, install will fail or need --with-all-dependencies gymnastics; a custom type is a lower-risk path than forking a 4-star, zero-dependent bundle.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource