bratsun
4/23/2014 - 1:58 PM

Wrap field collection fields up in a link (referenced entity).

Wrap field collection fields up in a link (referenced entity).

<?php foreach ($items as $delta => $item): ?>
  <?php if ($element['#field_name'] == 'field_fs_link') {
    print '<a class="doc-link" href="' . drupal_get_path_alias('node/'. $element['#items'][0]['target_id']) . '">';
  }
  
  // if it's first field in collection, open the link tag
  
  if ($element['#field_name'] != 'field_fs_link') { // hide first field (entity reference) content
  ?>
  
  <div class="f-<?php print str_replace('_','-',str_replace('field_','',$element['#field_name'])); ?> <?php print $classes; ?>"<?php print $attributes; ?>>
  
    <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; print ' field-item-'.($delta+1); ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div>
  
  </div>
  
  <?php 
  }
  
  // if it's last field in collection, close the link tag
  
  if ($element['#field_name'] == 'field_fs_teaser') {
    print '</a>';
  } ?>
<?php endforeach; ?>