I have created one module Color
I want to add this module to shopware 6 default module which is Category
Is it possible to add dropdown list with multiple select of Color when we add/edit Category
I did try to do it with custom field option, but my color module has multiple fields which I can use in front side.
The most straight forward way to do this would indeed be using custom fields. As you already noted the custom field referring to an entity will only contain a single value, by default the id of the entity. You can use the id to resolve the referenced entity when the category is loaded.
Step 1: Create the custom field
Step 2: Set up a subscriber to fetch the referenced entity from the id in the custom field when the category is loaded. To store your custom entity with the category entity you can use an extension.
Step 3: In the template you check for the extension and if it exists you can use the extension as an entry point to your custom entity.
Another way to this would be to use an
EntityExtensionto add a proper association from your custom entity tocategory. This will allow you to reference your entity when querying categories with the DAL, e.g. for filtering by color. From the point of performance this would also be preferable, but the implementation requires more steps. If you decide to go that route, I have an example repository where I add an association from a custom entity to thecustomerentity and manually add a field for it in the administration. Maybe this will be of help.