You are here

function entity_table in Entity Construction Kit (ECK) 7

Same name and namespace in other branches
  1. 7.3 eck.module \entity_table()
  2. 7.2 eck.module \entity_table()

Creates a table showing a group of entities.

Parameters

$entities: the entities to create the table from

$select: a boolean value that will determine whether the table is a select table or a regular table

1 call to entity_table()
eck__entity__overview in ./eck.entity.inc
This is the callback function for the entity overview page. This page shows all of the entities created of a given type and bundle

File

./eck.module, line 173
ENTITY CONSTRUCTION KIT

Code

function entity_table($entities, $select = FALSE) {
  module_load_include('inc', 'eck', 'eck.entity');

  //This is information set up for each bundle in the hook_entity_info

  //look there for more details
  $crud_info = NULL;
  $rows = array();
  $header = array(
    t('Name'),
    array(
      'data' => t('Operations'),
      'colspan' => '1',
    ),
  );
  $info = NULL;
  foreach ($entities as $entity) {
    $info = array();
    $entity_type = $entity
      ->entityType();
    $bundle = $entity->type;
    $id = $entity->id;
    if ($crud_info == NULL) {
      $crud_info = get_bundle_crud_info($entity_type, $bundle);
    }
    $edit_path = str_replace('%', $id, $crud_info['edit']['path']);
    $delete_path = str_replace('%', $id, $crud_info['delete']['path']);
    $uri = entity_uri($entity_type, $entity);
    $row = array(
      l(entity_label($entity_type, $entity), $uri['path'], $uri['options']),
    );
    $row[] = array(
      'data' => l(t('edit'), $edit_path) . "<br>" . l(t('delete'), $delete_path),
    );

    //"admin/structure/eck/{$entity_type}/{$bundle}/{$id}/delete"));
    $info['entity'] = $entity;
    drupal_alter("entity_{$entity_type}_{$bundle}_tr", $row, $info);
    $info['bundle'] = $bundle;
    drupal_alter("entity_{$entity_type}_tr", $row, $info);
    $info['entity_type'] = $entity_type;
    drupal_alter("entity_tr", $row, $info);
    $rows[$id] = $row;
  }
  if ($info) {
    unset($info['entity']);
    drupal_alter("entity_th", $header, $info);
    unset($info['entity_type']);
    drupal_alter("entity_{$entity_type}_th", $header, $info);
    unset($info['bundle']);
    drupal_alter("entity_{$entity_type}_{$bundle}_th", $header, $info);
  }
  if ($select) {
    if (!isset($entity_type)) {
      return array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => $rows,
      );
    }
    else {
      return drupal_get_form("entity_table_select_{$entity_type}_{$bundle}", $entity_type, $bundle, $header, $rows);
    }
  }
  else {
    return array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    );
  }
}