Written by Pete Corey on Feb 23, 2015.

Lately I’ve been playing with Orion, the fantastic Meteor based CMS. The way Orion builds on top of aldeed:collection2 and aldeed:autoform to create an incredibly flexible and powerful CMS is inspiring.

One feature I wanted out of Orion was the ability to have data from the dictionary be accessible from within an entity. For example, I wanted to keep a list of Categories in Orion’s dictionary and associate each Article entity with one of these categories. After doing a little digging, I found a way to accomplish this.

I’ve created a gist to show off this functionality. The key lines of code are shown below:

allowedValues: function() {
    return orion.dictionary.collection.findOne()['categories'];
},
autoform: {
    options: function() {
        return orion.dictionary.collection.findOne()['categories'].map(function(value) {
            return {
                value: value,
                label: value
            };
        });
    }
}

When setting up your entity’s attributes, you’ll need to add custom allowedValues and autoform functions. The allowedValues function returns the possible string values that can be saved into this field. These values are pulled from the categories field of the dictionary document. autoform is used to build the select options presented to the user. In this case, we’re using the category string as both the value and the label.

Interestingly, if allowedValues is not a function, it will build the options automatically. However, if allowedValues is a function, the dropdown will be empty. We need to explicitly specify a autoform.options function to build our options for us. I haven’t looked into what’s causing this.

These are issues with this approach. If a user creates an article with a certain category, but then deletes that category from the dictionary, the article will still hold the deleted value in its category field. When that article is edited in Orion, the category field will be blank. I’m hoping to spend a little more time in the future to address these issues and dig deeper into this kind of Orion functionality.