Repeatable fieldsets in Drupal: Inline Entity Form Vs Field Collection
My last post on field collections involved revisioning with Workbench Moderation and the issues faced. Since then the module has been developed further, but I've also come across a potential replacement: Inline Entity Form. Below is a short comparison of the two modules.
In this example I'll be adding a page with the ability to add a list of pets. The available fields will be the pet name, image, type (term reference) and a long text description field.
Creating the field
Before you can add the field you would need to create the entity you want to reference (in this case a node). After creating the 'Pet' node and needed fields you can then add the entity reference field to the page. When doing so you can select Inline Entity Form as the widget and will take you through the normal entity reference field options with the addition of 3 options (pictured).
When adding a field collection it is selected as the field type, with options to hide empty items and display a set number, or unlimited items. Once added you would then need to navigate to structure > field collections and add the fields to the created FC.
Adding the content
When creating a new page you're unable to view the needed fields until the 'add new node' button is clicked. Once done the fields appear as you would expect them to.
If you've opted to allow multiple nodes to be added the option for the user to do so doesn't appear until the 'create node' button is clicked and the added node saved. Once saved the added nodes appear in a list (seen below)
As with IEF, validation functions as expected.
Viewing the node
IEF & FC
Both of these function as you'd expect, displaying according to the 'manage display' settings of either the node or the field collection as needed.
Out of the box this sadly doesn't function, when creating a new draft and updating the existing linked nodes they're published when the new draft is created. There is an issue logged but with no recent updates you're forced to look elsewhere for a solution. I tried playing with the entityreference workbench sandbox module but wasn't successful.
The 'workaround' for this is to enable revisioning and moderation for the node type referenced and then publish them separately, this would mean that you're still unable to view the updated reference node within the page.
Working with beta7 this functions out of the box. Adding a new draft and modifying the FC values doesn't publish them until the whole node is published and you're able to view the draft content inline with the rest of the node.
The result of this can be seen below, where the top name/image is the Inline Entity Form, and the lower name/image is the field collection. The first showing the published page, and second showing the draft page.
The result is that Field Collections has come a long way, and while it still has issues it is definitely improving. Inline Entity Form may be able to provide the same moderation support as FC one day, but the ability to moderate sections of content on a page separately to the rest of the page may be useful depending on your requirements (often promoted alongside commerce/product solutions). This was just a brief test and demo and there may be issues with other functionality such as search (SOLR), multi lingual etc. As with most Drupal modules, you'll need to weigh up the pros and cons before deciding what is best for you and your project.
With thanks to James M for introducing me to Inline Entity Form.