You are here

protected function EntityPagerSetup::establishEntityInfo in Entity Pager 7

Establish the Entity Info from the View.

Use the View result to automatically establish the Entity type of interest. E.g. node or user etc.. Then return an array of information about the entity type and how the View is using it. E.g entity_type = "user" field = "uid" table = "users" alias = "uid"

Parameters

object $view: The View object.

Return value

array Get the entity info array.

1 call to EntityPagerSetup::establishEntityInfo()
EntityPagerSetup::establishEntity in includes/EntityPagerSetup.inc
Establish Entity.

File

includes/EntityPagerSetup.inc, line 373
General setup base Class for Entity Pager module.

Class

EntityPagerSetup
Class EntityPagerSetup.

Code

protected function establishEntityInfo($view) {
  $entity_info = NULL;
  $entity_keys = $this
    ->getEntityKeys();
  $view_fields = $view->query->fields;

  // Reverse order to get the last id e.g. nid or uid.
  rsort($view_fields);
  foreach ($view_fields as $view_field) {
    if (in_array($view_field['field'], $entity_keys)) {
      $entity_flip = array_flip($entity_keys);
      $entity_info = $view_field;
      $entity_info['entity_type'] = $entity_flip[$view_field['field']];
      break;
    }
  }
  return $entity_info;
}