You are here

function _relation_endpoint_field_create_html_table in Relation 7

Helper to create an HTML table representing a relation.

2 calls to _relation_endpoint_field_create_html_table()
relation_endpoint_field_formatter_view in ./relation_endpoint.module
Implements hook_field_formatter_view().
relation_endpoint_field_widget_form in ./relation_endpoint.module
Implements hook_field_widget_form().

File

./relation_endpoint.module, line 148
Relation endpoints field.

Code

function _relation_endpoint_field_create_html_table($endpoints) {
  $entity_info = entity_get_info();
  $list_items = array();
  foreach ($endpoints as $delta => $endpoint) {
    $entities = entity_load($endpoint['entity_type'], array(
      $endpoint['entity_id'],
    ));
    $entity = reset($entities);
    $label = entity_label($endpoint['entity_type'], $entity);
    $uri = entity_uri($endpoint['entity_type'], $entity);
    if ($uri) {
      $list_items[$delta] = array(
        l($label, $uri['path'], $uri['options']),
        $entity_info[$endpoint['entity_type']]['label'],
      );
    }
    else {
      $list_items[$delta] = array(
        $label,
        $entity_info[$endpoint['entity_type']]['label'],
      );
    }
  }
  $headers = array(
    t('Entity'),
    array(
      'width' => '22%',
      'data' => t('Entity type'),
    ),
  );
  return array(
    '#theme' => 'table',
    '#header' => $headers,
    '#rows' => $list_items,
  );
}