Collections 3

Introducing Selections, configurable buttons, context menu, resource type selection and more!

It has been almost an year since the first commit appeared in Collections repository and now Collections reached version 3 (If you still don't know Collections, you can read Collections: Customizable Views for Content Types article, that will give you an overview about what you can achieve with Collections).

The past

Before I introduce you all new features, let me wrap up Collection's past. It started as a simple extra with one purpose only - to hide resources from tree. I suppose we achieve that very well, because as the first version was released, we started to using them on all projects.

The first version get some nice updates with drag and drop sort, availability to drag children from the grid and drop it to the resource tree (to change it's parent, I still have no idea how I did that...) and of course Tagger support (more about Tagger should follow in the future, in a short, the best solution for tagging resources).

Then Revolution 2.3 was released and so do Collections 2 with Collection views (at first it was called Collection templates, which was a bit (a lot) confusing together with resource templates...). Within the second version came some great features - positionable content field, customisable tab label and new child label, new view's layout and a some more.

And now Collections 3, so let's take a look at it's new features!


How would I describe Selections? Favourite list of Resources? Virtual Collection? Resource Categories?

Selections is a new Custom Resource Type (CRC) which can't have any real children, but you can link any Resource to it. All linked Resources will appear in a same grid as Collections has (all views are working same here). So with this, you can build custom list of resources (for some specific menus, specific lists, etc.) without a need of duplicating resources or creating sym/web links.

One difference with Selections, whenever you have menu index column in a gird, it's not menu index of the real resource, but of the linked resource, that means, you can have all your favourited resources in specific order and don't break order of your tree (IOW, you can't screw up menu indexes for resources by changing their order in Selections).

With Selections comes also a new snippet getSelections. It is wrapper for getResources - you can use all options as you can with getResources (getResources are needed to proper Selections working; if you are using something other than getResources, you can change it in getSelections by parameter) which will let you list all linked resources for specified Selection (or Selections). By default it sorts by menu index of the linked resources.

Snippet column renderer

Sometimes JavaScript is not enough to show correct value for our columns. Sometimes you need more processing and MODX functions to get the right value (for example correct path for image from media source). To give you maximum control over your columns, you can now use not only JavaScript renderers, but also Snippet renderers.

Just input snippet name to Snippet renderer field (when updating a column in Collection views) and that's it. Oh, and of course, you have to write that snippet :P It takes value as an option (where is the original value of the column) and it returns modified value.

$value = $modx->getOption('value', $scriptProperties, '');
return strtoupper($value);

This snippet renderer will transform all your column values to upper case (not saying you need for this case Snippet renderer, just demonstrating how to create one ;)).

Snippet Renderer

Back buttons

Until now, you were able to get back to Collection with the close button. For someone it was unclear, because the close button didn't act like it does in all other resources. Now the close buttons acts as all others and new button is available: Back to Collection/Selection. (Update with option to customise text of this button is planed for next version!)

Customise everything

Customise everything

Context menu

In Collection view is available new option, where you can specify which items you'd like to include (and their order) to context menu for children's grid rows. Available option: view, edit, duplicate, publish, unpublish,& delete, undelete, remove, unlink, -

Some of them will be applied only for Collections and some only for Selections. The last one (-; dash) will create a horizontal line in the menu to separate options.

In-row buttons

You might noticed that some JS renderers (Collections.renderer.pagetitleWithButtons for example) also add buttons to your column. With this option you can specify which buttons it will be, their order and even their class.

Available options: view, edit, duplicate, publish, unpublish, delete, undelete, remove, unlink

Again, some of them will be applied only for Collections and some only for Selections. To specify a button class, simply add the class name after a colon ":". You can also add more class than one, for example "view,edit:orange red".

Resource types

For Collections, you can let users to choose which resource type they want to use when creating a new children. With this option, you can limit resource types that will appear in their list. It will also persist their order.

So for example to allow only new documents and selections you can specify this: "modDocument,SelectionContainer".

Resource types

Post By John Peca MODX