I feel that a widget type is missing for this module. One should be able to allow adding a field collection in a modal window.

On a new entity creation I would expect the widget to have 1 link available that says "Add new [field collection field]". When clicking it a new modal window would show that allows specifying values for the fields. Upon submission of the modal window it would close and the add/edit/delete links would be inserted into the place where the field might have been when using embedded widget. We could also add a summary of the values in the field collection so as to better know what is there.

Hope this makes sense, let me know if you have any questions. But I personally think this is an appropriate step for the UI of field collection module.

Comments

jlyon’s picture

I was able to achieve this using the ctools_automodal module. Search the issue queue for the 2.x branch and use the version of the module from github.

nicholas.alipaz’s picture

Thanks jlyon, I was a bit confused on what I should actually search for based on your comment, but I figured it out and found: #1701192: Start a 7.x-2.x branch of ctools_automodal

https://github.com/jlyon/ctools_automodal

I will test this when I get home, but I still think that the request seems to be in scope of what is provided by this module alone, or at least the portion which would simply output links in the edit and then integrate with another module possibly.

jlyon’s picture

Sorry about not linking to the issue/github fork directly. I was on my phone and couldn't find it easily.

Here's an example hook_modal_paths() call that will work. Just update the $field_collections array with your field collection name. I agree that it would be great if field_collections added this hook so that there was integration with ctools_automodal out of the box. It could also integrate with another module like modal or directly with ctools, but that seems a little unnecessary since you would need to use a lot of the logic that ctools_automodal already has.

Ways to improve this (I would be willing to work on this if there was interest):

  • Remove hard-coding of field collections to add modal treatment too, and either work out of the box for all collections, or add a checkbox to the ui to specify that a field collection edit form should appear in a modal.
  • Use the commands_callback entry in ctools_automodal to replace the value of the field_collections field without refreshing the entire page

/**
 * Implements hook_modal_paths().
 */
function example_modal_paths() {
  $paths = array();

  $reload_template = array(
    'style' => , // Create a style with hook_modal_styles() if you like
    'close' => TRUE,
    'reload' => TRUE,
    'redirect' => FALSE,
  );

  // Field collections
  $field_collections = array('field-coll-example');
  foreach ($field_collections as $field_collection) {
    $base = 'field-collection/' . $field_collection . '/%field_collection_item';
    $paths[$base . '/view'] = $reload_template;
    $paths[$base . '/edit'] = $reload_template;
    $paths[$base . '/delete'] = $reload_template;
    $paths['field-collection/' . $field_collection . '/add/%/%'] = $reload_template;
  }
}
seanB’s picture

Issue summary: View changes

Apparently there is not a lot support for this, but I think it's a great idea!
Will try the automodal solution...