Development Seed

Blog

Exportable and Spaces-Friendly Blocks in Drupal with the Boxes Module

The new Boxes modules provides custom blocks that play nicely with Spaces and Ctools

Earlier this week I added the Boxes module, which provides custom blocks that play nicely with Spaces and Ctools, to Drupal.org. I initially wrote the module for recent work we did on the World Bank's Open Atrium-based intranet, and at first I wasn't sure if it would be something that we'd want to maintain and release on Drupal.org, as it seemed rather project specific. However after using it on this project, it became apparent that we'll want to use the Boxes module on many projects and that the module could play a large role in making Open Atrium stronger out of the box.

Screenshot of the Boxes module for Drupal

The Boxes module has two primary purposes - to provide Ctools style exportable blocks and to integrate with the new 3.x branch of Spaces. Here is a brief screencast demonstrating a small part of what the module does.

The core block module provides a functionality for "Custom blocks", also occasionally called "Boxes" in the module's code, and it's fairly common for us to want to ship some blocks that use this functionality with a site launch or update. Before the Boxes module, we had two options on how to do this - we could either write an install (or update) script that creates these boxes, or we could hardcode the boxes in a custom module. An issue with the first option is that it's not possible to predict what the ID of the box will be, as it's generated from the sequential ID of the update, and this makes it hard to reference elsewhere in the site. And with the second option, the client needs to be a programmer to make even the smallest change to the text in the block. In reality, the default, normal, overridden model that modules like Views support is much closer to the functionality we want for blocks.

With the Boxes module, a site builder can package a block with a feature built for the site. The visibility of the block is controlled via a context that is also a part of the same feature. When the client needs to change the contents of this block, they can do so directly, without jumping through hoops or editing code.

As Boxes was built as part of an Open Atrium deployment, it was natural that we'd want to be able to customize these blocks or add new ones for each group on the site. Open Atrium let's you create any number of mini-sites (which we generally call groups as they're made using the Organic Groups module) that each have slightly different configurations. Boxes has Spaces module integration, which allows you to customize existing blocks for a specific group or create entirely new blocks that can only been seen and accessed in the space where they were created.

The Boxes module is available on Drupal.org, and if you're adventurous and handy with drush_make you can try it out today with the latest Open Atrium code from github.

core make

Hi!

How about this line: projects[] = “drupal”

Panels-like content choices?

Hi —

Nice work. I’ll go pull it down and play with it, but I thought I’d ask while I’m here: I’d like to be able to put standard-ish Drupal things into a box, the way Panels lets me do — whether it be a menu, a view, or the like.

It didn’t look from the video like Boxes provides anything more than a text area for the moment; am I just not seeing it (because I haven’t played with it), or is this a roadmap thing, or …?

Already possible

Manipulating any and all blocks in a dashboard is already possible. The drag and drop system in the demo is provided by the "Spaces Dashboard" module, a part of the Spaces 3.x project. It lets you add and arrange any block, whether provided by Boxes, Menu, Views, Mini-panels, etc...

Boxes roles is here is just to provide an inline interface for creating new custom blocks and editing them. Otherwise the blocks provided by Boxes are just like all other blocks on your site (except these are Space aware).

amazing!

I have got to try this one out in my site. Great job!

Very cool! Now we only

Very cool!

Now we only need an end-user friendly workflow for blocks revision control and so many usability issues disappear.

Amazing!!!

I love it! Definitely meets a need on d.o. I’ve run into the same problem w/ adding custom blocks to an install profile so definitely will be using this module.

Thanks for all your great work.

Wow

This is quite nifty. I don’t know what to say accept that this is really useful and I can’t wait to start implementing it. Great video also.

Ben J. from Vintage Digital sent the link through Skype this morning.

Cheers!