<p>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. </p>

<p>You can see how to create Plugins in the <a href="https://github.com/craftcms/docs/blob/v3/en/plugin-intro.md" rel="nofollow noreferrer">documentation</a> all available fields in Craft extends the base <a href="https://github.com/craftcms/cms/blob/develop/src/base/Field.php" rel="nofollow noreferrer">Field</a> class</p>

<p>There are function like <a href="https://github.com/craftcms/cms/blob/develop/src/base/Field.php#L279" rel="nofollow noreferrer">getInputHtml</a> where you define the html that should be displayed while you create your entry/category and the function <a href="https://github.com/craftcms/cms/blob/develop/src/base/Field.php#L345" rel="nofollow noreferrer">serializeValue</a> that defines which value should be saved into the db. </p>

<p>You should take a look at the default Craft <a href="https://github.com/craftcms/cms/tree/develop/src/fields" rel="nofollow noreferrer">fields</a> to get used to it. Change the values you need and create your own field.</p>

<p>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</p>

<p><strong>Edit</strong>
You can see how to register custom fields <a href="https://github.com/craftcms/docs/blob/v3/en/field-types.md" rel="nofollow noreferrer">here</a>. As you can see they say the same </p>

<blockquote>
  <p>You can refer to Craft’s own field classes for examples</p>
</blockquote>

CC BY-SA 3.0
2018-01-30T16:27:28.933Z
2018-01-30T16:58:34.337Z
2018-01-30T16:58:34.337Z
Robin Schambach
<p>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:</p>

<p><a href="https://i.sstatic.net/srkX0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/srkX0.png" alt="enter image description here"></a></p>

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

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

<p>Thank you.</p>

<matrix><craft3><custom-fieldtype>
Use a custom field type in Matrix Blocks - Craft 3
# Use a custom field type in Matrix Blocks - Craft 3

(Asked by: username_0 on 2018-01-30)

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](https://i.sstatic.net/srkX0.png)](https://i.sstatic.net/srkX0.png)

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.

**Tags:** matrix, craft3, custom-fieldtype


---

## 1 answers

### Answer by username_1 on 2018-01-30. Score: 2 | Accepted answer

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](https://github.com/craftcms/docs/blob/v3/en/plugin-intro.md) all available fields in Craft extends the base [Field](https://github.com/craftcms/cms/blob/develop/src/base/Field.php) class

There are function like [getInputHtml](https://github.com/craftcms/cms/blob/develop/src/base/Field.php#L279) where you define the html that should be displayed while you create your entry/category and the function [serializeValue](https://github.com/craftcms/cms/blob/develop/src/base/Field.php#L345) that defines which value should be saved into the db.

You should take a look at the default Craft [fields](https://github.com/craftcms/cms/tree/develop/src/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](https://github.com/craftcms/docs/blob/v3/en/field-types.md). As you can see they say the same

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


---

