Developers

Working on some custom functionality, or building out a new fieldtype? Bloqs was built with you in mind and comes packaged with some features to make your life as easy as possible.

Adding Fieldtype Support

Getting your field type working with Bloqs is a 3 step process, all of which are pretty straight forward. 

Step 1 - Your Field Type must be compatible with Grid

You’re going to start out the process by first getting your field type to be compatible with Grid. If you haven’t done this before, EllisLab has put together some excellent documentation to help you out with the process which you can find here: https://docs.expressionengine.com/latest/development/fieldtypes.html#grid-fieldtype-development 

Once your field type is compatible with Grid, you're just about there!

Step 2 - Opt in for Bloqs Support

The second step in the process is configuring your field to “opt in” to Bloqs support. This sounds tricky, but it’s really not. To do this, just modify the accepts_content_type method in your field type so that it also accepts content for “blocks/1”.

Here’s a simple and straight forward example you can reference:

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

 

Step 3 - Test

The third and final step in the process is to test everything out and make sure it's running smoothly. 

That's all there is to it!

Hooks

blocks_discover_fieldtypes

The blocks_discover_fieldtypes hook is called when Bloqs needs to determine which fieldtypes support Bloqs. Extensions may add or remove fieldtypes from the list of valid fieldtypes.

blocks_discover_fieldtypes is called with a single PHP array of stdClass objects, and should return that same PHP array, potentially modified.

The format of the objects within the array is as follows:

type – ExpressionEngine's identifier for the fieldtype. E.g. 'wygwam'.

version – The version of the fieldtype. E.g., '1.2'.

name – The human-readable name of the fieldtype. E.g. 'Wygwam'.

adapter (optional) – An object that serves as an adapter to a fieldtype. If the adapter is set, before Bloqs calls a method on the fieldtype, it first checks if the adapter has the same method, and calls it instead. If the adapter has asetFieldtype method, it will be called with the actual fieldtype that is being shimmed.

blocks_post_save

The blocks_post_save hook is called after Bloqs has finished saving.

The parameters that are passed to the hook are as follows:

  • blocks – The blocks that now belong to the field.
  • context – The context of the field, as an array.
    • $context['site_id']
    • $context['entry_id']
    • $context['field_id']