You are here

function party_attached_entity_content_type_render in Party 8.2

Same name and namespace in other branches
  1. 7 plugins/content_types/attached_entity/attached_entity.inc \party_attached_entity_content_type_render()

Render the custom content type.

File

plugins/content_types/attached_entity/attached_entity.inc, line 66
Plugin to handle attached entity content types

Code

function party_attached_entity_content_type_render($subtype, $conf, $panel_args, $context) {
  if (empty($context) || empty($context->data)) {
    return;
  }

  // Get a shortcut to the party.
  $party = $context->data;
  $data_set_name = $subtype;
  $data_set = party_get_data_set_info($data_set_name);
  if (!party_access('view', $party, $data_set)) {
    return;
  }

  // Get the attached entities in this data set
  $attached_entities = party_get_attached_entities($party, $data_set_name);

  // If there are none, do not render anything
  if (empty($attached_entities)) {
    return;
  }

  // Remove all unneccesary attached entities if we're not showing them all
  if ($conf['delta'] != -1) {
    $attached_entity_list = array_values($attached_entities);

    // If one with the right delta exists...
    if (isset($attached_entity_list[$conf['delta']])) {

      // Replace the array with an array just containing the one attached entity
      $attached_entity = $attached_entity_list[$conf['delta']];
      $attached_entities = array(
        $conf['delta'] => $attached_entity,
      );
    }
    else {
      return;
    }
  }

  // $attached_entities should now be alist of all the ones we want to show so lets convert this into a list of entities
  $entities = array();
  foreach ($attached_entities as $attached_entity) {
    $entities[] = $attached_entity;
  }
  if (empty($entities)) {
    return;
  }
  $block_delta = $data_set_name;
  if ($conf['delta'] != -1) {
    $block_delta .= '_' . $conf['delta'];
  }

  // Build the content type block.
  $block = new stdClass();
  $block->module = 'attached_entity';
  $block->title = $data_set['label'];
  $block->content = entity_view($data_set['entity type'], $entities, $conf['view_mode']);
  $block->delta = $block_delta;
  return $block;
}