Alter/insert into the links variable in a field_collection I am currently working with the Field Collection module, but I have stumbled into a small problem.

I am trying to alter the links variable (currently there is Edit &amp; Delete links) on a field_collection, as I want to add a link to it. I believe I have tried everything, such as hook_entity_view_alter(), or a preprocess function, but nothing seems to work.

Is there a way to solve this, without hacking core?
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(&amp;$output, $context) {
  if ($output['#entity_type'] == 'profile2' &amp;&amp; $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(&amp;$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' =&gt; 'links__field_collection_view',
  );
  $links['#attributes']['class'][] = 'field-collection-view-links';
  foreach (array('edit', 'delete') as $op) {
    if ($settings[$op] &amp;&amp; field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
      $links['#links'][$op] = array(
        'title' =&gt; $settings[$op],
        'href' =&gt; $field_collection-&gt;path() . '/' . $op,
        'query' =&gt; 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' =&gt; TRUE,
      'field-collection/*/*/delete' =&gt; TRUE,
      'field-collection/*/add/*/*' =&gt; 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' =&gt; 'drupal_get_form',
    'page arguments' =&gt; array('field_collection_item_form', $count),
    'access callback' =&gt; 'field_collection_item_access',
    'access arguments' =&gt; array('update', $count),
    'title' =&gt; 'Edit',
    'type' =&gt; MENU_LOCAL_TASK,
    'context' =&gt; MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' =&gt; 'field_collection.pages.inc',
  );