You are here

function eck__entity__overview in Entity Construction Kit (ECK) 7

This is the callback function for the entity overview page. This page shows all of the entities created of a given type and bundle

Parameters

$entity_type: (String) entity type

$bundle: (String) Bundle

1 string reference to 'eck__entity__overview'
eck__entity__menu in ./eck.entity.inc
This function creates the menu items related to entity administration

File

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

Code

function eck__entity__overview($entity_type, $bundle) {
  $info['entity_type'] = $entity_type->name;
  $info['bundle'] = $bundle->name;
  $table = "eck_{$entity_type->name}";

  // @todo Mabye I should use entity field query
  // Get all entity instances of this type
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', $entity_type->name, '=')
    ->entityCondition('bundle', $bundle->name, '=');
  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();
  }

  //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);
  $build['add'] = array(
    '#markup' => "+ " . l(t('Add Entity'), $crud_info['add']['path']),
  );
  $build['table'] = entity_table($entities, TRUE);
  $build['sample_code'] = array(
    '#theme' => 'form_element',
    '#title' => t('Optional entity type class'),
    '#description' => t('You may add this custom class for the bundle. To create a new instance of this class programmatically call: %code', array(
      '%code' => "entity_create('{$entity_type->name}', array('type' => '{$bundle->name}'));",
    )),
    '#children' => "<pre>" . check_plain("class " . eck_get_class_name($bundle->name, 'EntityType') . " extends Entity{\n\n}") . "</pre>",
  );
  return $build;
}