Apr
9
2014

What are “Element Types” in Craft?

One of the key innovations in Craft – make that the key innovation – is a new concept called “Element Types”. We’ve mentioned Element Types here and there, but we haven’t explained what they are yet, much less how plugins can take advantage of them.

Now that Craft 2 is out, we’re finally ready to lift the curtain.

Before we can get into Element Types, let’s first identify what an “element” is.

File systems manages files. iPhoto manages photos. iTunes manages media. Blogging systems manage entries. And content management systems manage… “content”. But what is “content”? Historically it has meant “entries”, in the exact same sense as blogging systems (albeit with more varieties). Sure, they also usually manage other things like users, files, and categories, but those are just second class citizens. Entries still have all the fun – custom fields, relations, etc..

While other content management systems are busy managing entries, Craft manages elements. Everything in Craft – your site’s users, assets, categories, tags, globals, even Matrix blocks, and of course, entries – they’re all elements. That’s why everything is so consistent in Craft. It’s not that entries and users both individually have custom field support, it’s that they share the same system-wide custom field support that’s available to all elements. Same with relations, and a slew of other things.

So if the individual users, assets, categories, tags, globals, and entries are the elements, what are Element Types?

Element Types are the classes used to identify each of these types of elements in Craft. There’s a “UserElementType”, there’s an “AssetElementType”, and so on. If you’ve ever developed a custom Field Type class before, this should sound familiar. The relationship between an element and an Element Type is the same as that between a field and a Field Type.

Due to its size and scope, it has taken us a long time to get the Element Type APIs to a point where we’re happy with them and ready to start sharing them with plugins. That time has finally come, though: as of Craft 2, the veil has been lifted and plugins are welcome to start adding their own Element Types.

Yesterday we gave a private demo of the APIs to a handful of plugin developers, and the level of excitement in the room was palpable. It doesn’t take long to realize what great potential there is here.

In two weeks we will be giving a three-hour workshop on Element Type development at Peers. If you are a developer with any interest in writing plugins for Craft, I highly recommend you come to that. You really won’t want to miss this opportunity!

comments powered by Disqus