1

I'd like to create a field of type Dropdown/Table (or even use a field from a plugin like color-swatches) and have it available when selecting a matrix block element field type:

enter image description here

In this case, it's for creating a field containing a set of color values, a palette.

I'd like to know whether or not this is a common approach and what solutions do you usually give to this.

Thank you.

2

I'm not sure what it has to do with a matrix - you can use every field normally and inside a matrix, there is no restriction - but I usually create a custom field type.

You can see how to create Plugins in the documentation all available fields in Craft extends the base Field class

There are function like getInputHtml where you define the html that should be displayed while you create your entry/category and the function serializeValue that defines which value should be saved into the db.

You should take a look at the default Craft fields to get used to it. Change the values you need and create your own field.

However: I think the most common approach is to look what Pixel and Tonic does and understand how it works. Then you can create custom fields via Plugin or Module

Edit You can see how to register custom fields here. As you can see they say the same

You can refer to Craft’s own field classes for examples

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.