Oh The Huge Manatee

A blog about technology, open source, and the web... from someone who works with all three.

On Drupal Entities, or How Organic Groups and Taxonomy Are the Same Thing

I’m a big fan of the new Entities model for Drupal. I’ve been working a lot with it lately, and it makes a lot of sense… but my favorite part is how it keeps blowing away my old assumptions, inherited from 7 years of Drupal experience.

Here’s a big one that got me recently: Organic Groups is useless, because it’s basically Taxonomy with a couple of neat add-ons. Or Organic Groups is incredibly useful, however you choose to think about it.

Let’s think about Taxonomy from the perspective of what it actually accomplishes. It’s a fieldable (thanks D7) way to group content. Each Taxonomy Term is an object on its own, which is referenced by other content to provide groupings. There’s nothing there that you can’t do with a generic entity, entityreference module, and a block view on taxonomy landing pages.

In D4-D6, Taxonomy was the best way to categorize content, especially if you want that categorization to be hierarchical in nature. Period. In D7… meh. You can build an entity that replaces taxonomy incredibly easily. In this sense, Taxonomy is useless. It could be removed from Drupal core, and treated as a great example of a well fleshed out Entity that fills a common use case. I look forward to seeing taxonomy reference replaced by entityreference, which will make the transformation complete.

ON THE OTHER HAND, having this pre-built entity is incredibly useful. Because Taxonomy IS a good implementation of the Entity model, it is flexible enough to obsolete a lot of more complex modules in a lot of use cases… and saves you a fair amount of coding and configuration in the meanwhile.

Now, I am a huge fan of Organic Groups, and in D6 it was the number one way to give flexible content groupings with any kind of membership. It always bugged me how much configuration you had to do for the simplest of Group structures, though. And in D7… now you can do a lot of what Organic Groups does with the Taxonomy Entity. I didn’t think this was so until I really thought it through, and had an example to work with.

So I had a site where we wanted to provide schedules for every user on the site, and allow Events to be scheduled for arbitrary groups as well. Each group should have a landing page with its own calendar for the group and all sub-groups. For example, the group calendar for “Company Executive” should include events for “Vice Presidents”, “Chiefs”, and “Chairpeople”. Group membership is all centrally managed. And if you’re a member of a group, you should receive update emails for every event that gets added to your group.

In D6 this was a perfect use case for Organic Groups. In D7, I decided to do this with taxonomy instead. Why? The Ux for hierarchy creation and management is better in taxonomy because of the vast contrib ecosystem for it. What I would have built with Views, EntityReference, and custom code for nice hierarchical Ux in OG, is 80% built for me from day 1 with Taxonomy. Just apply the “Groups” taxonomy to the user object and the content types you want, and bam - you’ve just put Users and Content into semantic groups together. That’s what OG, at it’s core, provided for us in D6… and with some pre-built Views, is all it provided for a lot of projects.

This led me down an interesting path of thought. What is the point of OG, if Taxonomy can duplicate its functionality so handily?

And it dawned on me: all Organic Groups really offers is a fieldable Entity that interacts with Permissions in a way that is common for user-created groups. We could do this with Taxonomy and some custom code: write a module that offers permission limitations based on taxonomy term association with the user object, and then include a nice UI for adding terms to your user object by clicking a link on the taxonomy term page… you’ve got a solid competitor for OG. And at that point, I would start saying things like “why did you bother using Taxonomy, when OG would have done it out of the box?”

And I think that’s when I really got the power of entities. We’ve been used to seeing modules as a way to provide extra capabilities to Drupal. They can still do that, of course. But many of the best modules will just offer pre-configured Entities for popular use cases. Like an Entity that groups users and content, offers a way for users to join groups conveniently, and gives Permissions ramifications for group membership. Or an entity that lets you group other entities semantically into a hierarchy. The complex Organic Groups and the simple Taxonomy are only a couple of steps removed from each other… and both great examples of Entities in action.