apostrophecms / docs

ApostropheCMS documentation.
MIT License
4 stars 14 forks source link

[DOCS ISSUE] Page: attachment - Custom File Groups #246

Closed LeviticusMaximus closed 2 years ago

LeviticusMaximus commented 2 years ago

Hi,

In the docs it states:

Developers can configure file type groups in addition to office and image using the fileGroups option of the @apostrophecms/attachment module. Those custom groups names can then be used for an attachment field's fileGroup setting.

Can you give me a bit more information about how I would do this please? I would like to add an mp4 option. I guess that I could download the github @apostrophecms/attachment/index.js and create a local version in a new folder in modules/@apostrophecms/attachment and then add another fileGroup something like the following:

self.fileGroups = self.options.fileGroups || [
      ...
      {
        name: 'localVideo',
        label: 'apostrophe:localvideo',
        extensions: [
          'mp4'
        ]
      },

But I'm wondering if there's a simpler method that doesn't involve duplicating the whole index.js file?

Thanks

boutell commented 2 years ago

cc @BoDonkey

BoDonkey commented 2 years ago

Hi @LeviticusMaximus, Sorry I missed this. At the moment you can elect to replace the entire fileGroups array through an option in the /modules/@apostrophecms/attachment/index.js file. You can also alter the existing one from within that same file. Basically you would do something like this:

module.exports = {
  init(self) {
    const newGroup = {
      name: 'localVideo',
      label: 'apostrophe:localvideo',
      extensions: [ 'mp4' ],
      extensionMaps: {}
    };
    self.fileGroups = [ ...self.fileGroups, newGroup ];
  }
};

So you are just adding the new group in place. Note, you need to add the extensionMaps property with an empty object. I'm not sure why the module is glitching about this. I have to look closer at the logic in this module.

I'm implementing an easier way to do this using a fieldGroupsAdd option. Might be out soon. Cheers