In one of our projects we have News page type. It has a “see more” section with links to other news pages. When editor is creating New page, he adds few articles to “see more” section. In some situations he would like to pick few random pages. I extended ContentArea with adding random items functionality.
Adding random items to ContentArea

The random list will be generated on server side and returned by REST controller. It’s a simple implementation which use FindPagesWithCriteria to get list of available pages. After loading collection, three random items are returned.

In module initializer, the JsonRest store is registered under the “randomContentStore” key.

The module initializer is set in clientModule section of module.config and it will be executed during loading framework.

The widget inherits from ContentArea editor and adds additional “Add random items” link. It has to be added after standard “create a new block” action, so createAddRandomElementsAction method is executed when getTemplateString is resolved. In link click event the REST service is called and random elements are added to the ContentArea.

Adding random items to ContentArea demo

The full source code is available on Gist