<p>Got there in the end and very simply through:</p>

<pre><code>use Craft;
use craft\fields\BaseRelationField;
use craft\elements\Category;

class Categories extends BaseRelationField
{

    public static function displayName(): string
    {
        return Craft::t('app', 'Categories (multiple)');
    }

    protected static function elementType(): string
    {
        return Category::class;
    }

    public static function defaultSelectionLabel(): string
    {
        return Craft::t('app', 'Add a category');
    }
}
</code></pre>

<p>So simple</p>

CC BY-SA 3.0
2018-03-28T16:17:26.207Z
2018-03-28T16:17:26.207Z
Cole Henley
<p>Isnt this possible with the <code>modifyCategorySources</code> hook?</p>

<p>-> <a href="https://docs.craftcms.com/v3/extend/updating-plugins.html#modifyentrysources-modifycategorysources-modifyassetsources-modifyusersources" rel="nofollow noreferrer">https://docs.craftcms.com/v3/extend/updating-plugins.html#modifyentrysources-modifycategorysources-modifyassetsources-modifyusersources</a></p>

<p>I'm assuming you are using C3 by the namespace you mentioned. Correct me if this is wrong :). </p>

CC BY-SA 3.0
2018-03-28T15:47:17.670Z
Not entirely sure that is quite what am after. Want to create a new field type (rather than globally affect existing one) so that multiple category sources can be specified. Does that make sense?
Cole Henley
CC BY-SA 3.0
2018-03-28T16:06:36.223Z
Suppose really wondering whether you can `extends BaseRelationField` for your field as is the case with the existing Element Type fields
Cole Henley
CC BY-SA 4.0
2018-03-28T15:10:36.737Z
2018-11-02T18:42:20.303Z
2018-11-02T18:42:20.303Z
Gįëł Tėttëłæår
<p>I want to utilise the Category field type but with the ability to choose from multiple category sources (as with Entries).</p>

<p>I noted in <code>cms/src/fields/Categories.php</code> that <code>$this-&gt;allowMultipleSources</code> is set to false. What is the simplest way of changing this to true without changing the source file?</p>

<p>Can I create a custom field that essentially just extends the original Category field but with <code>$this-&gt;allowMultipleSources</code> set to true?</p>

<plugin-development><categories><craft3><field><custom-fieldtype>
Multiple Category Sources Field
# Multiple Category Sources Field

(Asked by: username_0 on 2018-03-28)

I want to utilise the Category field type but with the ability to choose from multiple category sources (as with Entries).

I noted in `cms/src/fields/Categories.php` that `$this->allowMultipleSources` is set to false. What is the simplest way of changing this to true without changing the source file?

Can I create a custom field that essentially just extends the original Category field but with `$this->allowMultipleSources` set to true?

**Tags:** plugin-development, categories, craft3, field, custom-fieldtype


---

## 2 answers

### Answer by username_0 on 2018-03-28. Score: 1

Got there in the end and very simply through:
use Craft;
use craft\fields\BaseRelationField;
use craft\elements\Category;

class Categories extends BaseRelationField
{

    public static function displayName(): string
    {
        return Craft::t('app', 'Categories (multiple)');
    }

    protected static function elementType(): string
    {
        return Category::class;
    }

    public static function defaultSelectionLabel(): string
    {
        return Craft::t('app', 'Add a category');
    }
}

So simple


---

### Answer by username_1 on 2018-03-28. Score: 1

Isnt this possible with the `modifyCategorySources` hook?

-> <https://docs.craftcms.com/v3/extend/updating-plugins.html#modifyentrysources-modifycategorysources-modifyassetsources-modifyusersources>

I'm assuming you are using C3 by the namespace you mentioned. Correct me if this is wrong :).

> **Comments:**
> **username_0**: Not entirely sure that is quite what am after. Want to create a new field type (rather than globally affect existing one) so that multiple category sources can be specified. Does that make sense?  
> **username_0**: Suppose really wondering whether you can `extends BaseRelationField` for your field as is the case with the existing Element Type fields  

---

