You are here

function eck__entity__list in Entity Construction Kit (ECK) 7.3

Same name and namespace in other branches
  1. 7.2 eck.entity.inc \eck__entity__list()

Entity overview page callback.

1 string reference to 'eck__entity__list'
eck__entity__menu in ./eck.entity.inc
Entity related menu items.

File

./eck.entity.inc, line 190
All the menus, pages, and functionality related to administering entities.

Code

function eck__entity__list($entity_type_name, $bundle_name) {
  $entity_type = entity_type_load($entity_type_name);
  $bundle = bundle_load($entity_type_name, $bundle_name);
  $info['entity_type'] = $entity_type->name;
  $info['bundle'] = $bundle->name;
  $table = "eck_{$entity_type->name}";

  // Get all entity instances of this type.
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type->name, '=')
    ->entityCondition('bundle', $bundle->name, '=')
    ->pager(20);
  drupal_alter('entity_overview_query', $query, $info);
  unset($info['entity_type']);
  drupal_alter("entity_{$entity_type->name}_overview_query", $query, $info);
  drupal_alter("entity_{$entity_type->name}_{$bundle->name}_overview_query", $query);
  $results = $query
    ->execute();
  if (!empty($results)) {
    $entities = entity_load($entity_type->name, array_keys($results[$entity_type->name]));
  }
  else {
    $entities = array();
  }
  $destination = drupal_get_destination();

  // Because of the flexible paths capabilities, we are not guaranteed to see a
  // local action for the add here, so lets add a link ourselves until we figure
  // out whether there is a better solution.
  $crud_info = get_bundle_crud_info($entity_type->name, $bundle->name);

  // Check that the user has permissions to add an entity:
  if (eck_access('create', 'entity') || eck_access('create', 'entity', $bundle)) {
    $build['actions'] = array(
      '#theme' => 'links',
      '#links' => array(
        array(
          'title' => t("Add") . " {$bundle->label}",
          'href' => $crud_info['add']['path'],
          'query' => $destination,
        ),
      ),
      '#attributes' => array(
        'class' => array(
          'action-links',
        ),
      ),
    );
  }
  $build['table'] = entity_table($entities, TRUE);
  $build['pager'] = array(
    '#theme' => 'pager',
  );
  return $build;
}