3

I have made a field collection, exported as a Feature and now I'd like to add it to a block. Does anyone have any suggestions? I have added fields to blocks through the form API, but that doesn't seem to apply here.

I would like to add this field collection through code, rather then finding a module.

I've looked at hook_block_configure to add the form there, but I don't know if I can add a type that isn't listed in Form API reference.

1
  • Field collection or paragraph type cannot be added to blocks. Commented Oct 3, 2017 at 19:58

3 Answers 3

3

How about doing it through Views.

You can create a block view, add your field collection to the view, then use the view as a block.

2
  • This is perfectly valid, but I rather use the Bean solution as you don't have to worry about having a page url and not having google indexing it.
    – No Sssweat
    Commented May 11, 2016 at 0:22
  • 1
    There is no need to create a view page. Simply create a view as a block as suggested by Hayk. Unless you already have the BEAN module enabled for something else AND OR don't have views installed, I would suggested using views. (1 less module) Commented Oct 3, 2017 at 17:27
2

With the default Block system you can't add fields to Blocks.

You can use the Bean module, which converts Blocks into Entities. Then you will be able to add fields to it.

3
  • I know you can't add fields to the Blocks through the UI, but what about through hook_form?
    – spuppett
    Commented May 11, 2016 at 12:48
  • Or not through hook_form specifically, but through code more generally?
    – spuppett
    Commented May 11, 2016 at 12:55
  • You can use hook_block_configure() to add form configuration to a block but adding a Field Collection that way isn't possible.
    – albertski
    Commented May 11, 2016 at 15:45
1

You really need to have a look at the Bean to answer this question. Here is a quote about its project page:

Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.

This module also works great in combination with the UUID and UUID Features Integration modules.

The video tutorial Drupal Bean module tutorial - using Bean Admin UI provides a great introduction to really understand the power of this module, and the kind of things you can do with it. It also shows how the Bean module transforms Drupal blocks into fieldable entities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.