Array of strings type Fieldtype

Hi everyone, i’m struggling to make an array of strings field type.
I’m using the ‘tags’ field type, but i need to be able to repeat values on the array, and the tags field type is not helping :frowning:, at least using cockpit from the web interface.
Is there a way to allow tags to be repeated in the same field?

Sorry to bother again, but no one knows how to allow same tag names in “tags” field from backend?

Hey @mpw,

If you want something similar to taxonomies (tags), you have many options, e.g.:

Create a collection (named tags) and have a collection link (multiple) linking to tags collection.
Create a repeater field that has only one text field.
Create your own field with the functionality you need, you can copy the cockpit/assets/components/field-tags.tag to your addon (with a different name) and make the changes there.

Hope that helps.

1 Like

Thanks @pauloamgomes, i’ll try to create my own field, because using a collection link screws up my ‘desired’ json structure

Ok, but remember that you can hook on the API and change the json, for example, let’s imagine you are using a collection link for tags, but you only want in the json the name (not the default attributes like _id, modified, etc…), you can create:

$app->on('collections.find.after.myCollectionName', function ($name, &$entries) use ($app) {
  foreach ($entries as $idx => $entry) {
    $entries[$idx] = $entry['name'];
  }
});

so when fetching a collection that links to “myCollectionName”, the linked field will have only the name as result.

1 Like