Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

 

To infinity… and beyond!

SilverStripe developer Simon Erkelens reviews Milkyway Multimedia module.

Read post

Milkyway Multimedia has bundled some of its useful extras to the core and CMS in a set of modules and published them on github.

The modules are split up into a set of basic useful modules: core, env, assets, flashmessage, and shortcodes. To install them all, there’s ss-mwm-utilities that requires all of them via composer.

composer require milkyway-multimedia/ss-mwm

Core contains basic things added to the CMS, Director, Controller, DataObject etc. adding some useful functionality.

Assets is a “new Require”. The name is a bit confusing— at first, I thought it was about asset admin. As it turns out, it adds features to the Requirements.

Flashmessage is a very nice one. We know it all too well. Having to set messages on the frontend, writing a whole bunch of code just for one success/error message.

Shortcodes gives you some extras to work with in the CMS. Together with Shea Dawson’s module, the CMS gets some extra default (and working) shortcodes.

Code quality

If it were okay for me to (peer-)review the mwm module, which recently appeared on our addons website, here would be my humble response: "I need all the help, constructive feedback and suggestions I can get since backend programming is not my main field, you may notice by the lack of tests I write, and am still learning test driven development."

Because of this, I first had a look at the code, which turned out to be not so rookielike at all.

Admittedly, there are missing tests. The code isn’t always up to my quality standards (although I have to say the code quality I try to impose even annoys my teammates sometimes) but it’s decently written. The main problem I encountered was a lack of documentation or very long functions that sometimes were a bit confusing.

Also, I can see some features ending up in the core actually.

Core

CMS Functionality

Screen Shot 2016 04 19 at 19.33.22The mwm-core module adds some nice features to the CMS. Low and behold— a feature I’ve always thought might be useful was suddenly there! Yep, that’s Publish, Unpublish and Delete permanently, right there. There are a few more features that I haven’t tested yet, or have been unable to use due to possibly config settings.  But that’s okay—you can check them out yourself.

Backend stuff

There’s a lot more under the hood.

Utilities

The base Utilities class incorporates some global extras. Like looking up countries and month names. Although this may sound trivial, have you ever heard of someone saying “Ah, time and date methods, I love them”? I haven’t for sure. So every bit of help in that area is welcome. Some methods are a bit redundant, like is_instanceof basically being a copy of is_a.

CookieJar

This class adds updateConfig to the CookieJar class. Quite basic, requires the env module.

DataObject

Where the Folder class already implements a findOrMake() method, DataObject in itself doesn’t do that. The DataObject extension in MWM-Core adds this method, although named “firstOrMake” or “firstOrCreate” instead of “findOrMake”. Could be useful, since I often do

$object = Object::get()->first();
if($object !== null) {
        $object->manipulations;
}
else {
        $object = Object::create();
        $object->manipulations();
}

With firstOrMake or firstOrCreate, the days of doing the extra if/else should be a thing of the past.

Controller

Something that interested me is the Controller::getBackLink() method. It does exactly what you’d expect. It gives you the URL that Controller::redirectBack() would redirect you to.

That’s useful as you don’t always want to send someone back, but at the same time, do give the option to click on “go back where I came from” from template. To be honest, I’ve personally always been annoyed by not having such a simple method.

Director

Next, there are some extras on Director. Like the creation of default pages, with a bit more options than those available in the core Director. A method I liked was the quick and easy way of returning an AJAX response, by calling Director::ajax_response($rawData, $statusCode, $status), you have an instant json response, a json like this:

{
     ‘status’: $status,
     ‘code’: $code,
     'Content': $rawData
}

Admitted, this could use some consistency updates, with status and code being fully lowercase, but Content starting with an uppercase C. But still. It will give you a consistent response every time, on which you can rely to easily parse in your javascript and always know which is which.

DBField

Further on, some additions to DBField. Methods like nl2list(), nl2numbered() and nl2br() provide you with the easy option to give customers a blank textarea, and make a list of the escaped XML value, by just starting on a new line. Not bad at all.

Assets

Assets is not really assets. It’s require. And it has some neat features, to defer, or prioritize loading of external assets or CSS. Using the defer method, you can defer loading of CSS and/or javascript until after the page has been loaded.

Also, it has a Lorem Ipsum method. If you want to have a demo-site setup quickly and have some content without worrying about it, just $loremIpsum($paragraphs = 1, $length = 'short', $opts = ['plaintext']) in your template, and Bob’s your uncle! (Of course passing the parameters correctly).

There’s a little problem with strictness in this module, since it’s calling a non-static function, but I assume that will be fixed soon. And admittedly, I have the warning level of PHP quite high set, so it might just be my machine.

Also, there’s a $placeIMG() method for the templates, so you can put in placeholder images to further show off your showcase.

Flashmessage

I have hardly ever been happy with flash messages. I mean it. They’re terrible to build. And you have to go around fiddling in the session or sessioncontainer etc.

Much to my delight, the flashmessage solves this for me. Although not entirely suitable for my own website, since it seems to interfere with my own template, but here’s an example:

My Page_Controller init method. I figured it would be a nice place to add a message:

Screen Shot 2016 04 23 at 15.23.52

Result!

Screen Shot 2016 04 25 at 11.19.07

Well, yeah, that’s my website on my local machine. It’s that simple! And there’s also error/success, of course. And note which displays a popup.

Even overriding the styling is quite easy to implement, or just do it in your own CSS of course.

Shortcodes

Basically, together with Shea Dawson’s shortcodable module, you now have some nice default shortcodes available in the CMS Editor. For example, add a FontAwesome Icon into the content. Or a search option.

Formfields

Finally, there’s also a Formfields module, but it has a big warning sign telling you not to use it yet. So we’ll have to wait and see what it’s going to be.

From the looks of it, a lot of extra form fields to be used in your forms. Which is obviously a dead giveaway considering its name.

In conclusion

The Milkyway Modules have a lot of nice extra features you (re-)write every day because nobody came up with a module for it. Now, there is.

It’s not perfect or fully tested. I did find some bugs. But it gives you a lot of tools to work with and help you spend more time making your client happy than doing basic stuff you do over and over for every website.

There’s a lot more to this module than what I’ve described here. Have a look yourself and let the author know what to improve. She’s very open to suggestions and keen to learn.

Give it a shot—feed back to @mi3ll or make some issues on Github.

Header image by Tom Hall.

About the author
Simon Erkelens

Simon is a developer at SilverStripe. When not at work, he's writing other programs or focusses on one of his modules he wrote or co-wrote. Or writing new things.

As a real backend developer, he's usually staring at a dark screen with code only. Although every now and then, he can be convinced to work on some frontend things or testing.

In real life, he looks nothing like the cow in his avatar, but he does love cows (both alive and medium rare)

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments