You are here

function paragraphs_pack_field_formatter_view in Paragraphs pack 7

Implements hook_field_formatter_view().

File

includes/paragraphs_pack.formatters.inc, line 157
Implements custom formatters: PP_FORMATTER_VIEW_MODE

Code

function paragraphs_pack_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $result = array();
  $settings = $display['settings'];

  // Rebuild the items list to contain only those with access.
  foreach ($items as $key => $item) {
    if (empty($item['access'])) {
      unset($items[$key]);
    }
  }
  switch ($display['type']) {
    case PP_FORMATTER_VIEW_MODE:
      foreach ($items as $delta => $item) {

        // Protect ourselves from recursive rendering.
        static $depth = 0;
        $depth++;
        if ($depth > 20) {
          throw new EntityReferenceRecursiveRenderingException(t('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array(
            '@entity_type' => $entity_type,
            '@entity_id' => $item['target_id'],
          )));
        }
        $entity = clone $item['entity'];
        unset($entity->content);
        $result[$delta] = entity_view($field['settings']['target_type'], array(
          $item['target_id'] => $entity,
        ), $item['view_mode'], $langcode, FALSE);
        if (empty($settings['links']) && isset($result[$delta][$field['settings']['target_type']][$item['target_id']]['links'])) {
          $result[$delta][$field['settings']['target_type']][$item['target_id']]['links']['#access'] = FALSE;
        }
        $depth = 0;
      }
      break;
  }
  return $result;
}