Field Type Development

Do you want your field type to work with Blocks? Great! I do to.

Blocks leans strongly on ExpressionEngine's native grid field type development. It does this mainly to make things easy for field-type developers like you.

So, the first thing you should do is make sure your field works with Grid. Oh, it does already? Good. You're 90% of the way there. Probably more.

Blocks could just say that any field type that supports Grid also supports Blocks. Actually, I was going to go that way for a long time. The problem that runs into, though, is that some poor unsuspecting field-type developer might get opted in to a system they have never even seen, something goes just slightly wrong, and they're stuck with some bug report on something they've never heard of. It's a bad experience for Blocks, a bad experience for the field-type developer, and a bad experience for whoever tried using the field-type with Blocks. No, I don't want that.

Instead, although Blocks only uses Grid methods – grid_display_settings, grid_save, etc. and even the Grid JavaScript library – you as the field-type developer need to opt in.

Opting-in is as simple as modifying your accepts_content_type code to also accept blocks/1. That's it.

public function accepts_content_type($name)
  return ($name == 'channel'
    || $name == 'grid'
    || $name == 'blocks/1');

Test to make sure everything works and publish away. Easy peasy.