In a custom module you can use hook_field_attach_view_alter(). In this example I'm using the distribution profile eRecruiter so there is a bundle called resume with several field collections and in an entity type profile2. Every time there is a field attached to a field collection this hook is fired recursively but the links are not contained there.
/**
* Implements hook_field_attach_view_alter()
*
* @param mixed $output
* @param mixed $context
*/
function helper_field_attach_view_alter(&$output, $context) {
if ($output['#entity_type'] == 'profile2' && $output['#bundle'] == 'resume') {
$f = 'do stuff here';
}
}
So you understand how the links work here is some of the code used in field_collection.module.
The links are created in a render array. Don't worry about 'links__field_collection_view' too much because it doesn't do anything. When the #theme function is called more familiarly as theme('link__field_collection_view', $variables) it looks first for TEMPLATE_link__field_collection_view(&$variables) or link--field-collection-view.tpl.php however if it doesn't find it, it will use as it does in this case theme_links();
$links = array(
'#theme' => 'links__field_collection_view',
);
$links['#attributes']['class'][] = 'field-collection-view-links';
foreach (array('edit', 'delete') as $op) {
if ($settings[$op] && field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
$links['#links'][$op] = array(
'title' => $settings[$op],
'href' => $field_collection->path() . '/' . $op,
'query' => drupal_get_destination(),
);
}
}
hook_admin_paths() is used to make the links rendered in the dialog window.
function field_collection_admin_paths() {
if (variable_get('node_admin_theme')) {
return array(
'field-collection/*/*/edit' => TRUE,
'field-collection/*/*/delete' => TRUE,
'field-collection/*/add/*/*' => TRUE,
);
}
}
hook_menu() is set up for the link callback in this case the edit link
$items[$path . '/%field_collection_item/edit'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('field_collection_item_form', $count),
'access callback' => 'field_collection_item_access',
'access arguments' => array('update', $count),
'title' => 'Edit',
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'field_collection.pages.inc',
);