You are here

public static function EntityFieldHandlerHelper::construct_property_selector in Entity API 7

Return an Entity API data selector for the given handler's relationship.

A data selector is a concatenation of properties which should be followed to arrive at a desired property that may be nested in related entities or structures. The separate properties are herein concatenated with colons.

For instance, a data selector of "author:roles" would mean to first access the "author" property of the given wrapper, and then for this new wrapper to access and return the "roles" property.

Lists of entities are handled automatically by always returning only the first entity.

Parameters

$handler: The handler for which to construct the selector.

$complete: If TRUE, the complete selector for the field is returned, not just the one for its parent. Defaults to FALSE.

Return value

string An Entity API data selector for the given handler's relationship.

3 calls to EntityFieldHandlerHelper::construct_property_selector()
EntityFieldHandlerHelper::click_sort in views/handlers/entity_views_field_handler_helper.inc
Adds a click-sort to the query.
EntityFieldHandlerHelper::get_value in views/handlers/entity_views_field_handler_helper.inc
Get the value of a certain data selector.
EntityFieldHandlerHelper::pre_render in views/handlers/entity_views_field_handler_helper.inc
Load the entities for all rows that are about to be displayed.

File

views/handlers/entity_views_field_handler_helper.inc, line 194
Contains the EntityFieldHandlerHelper class.

Class

EntityFieldHandlerHelper
Helper class containing static implementations of common field handler methods.

Code

public static function construct_property_selector($handler, $complete = FALSE) {
  $return = '';
  if ($handler->relationship) {
    $current_handler = $handler;
    $view = $current_handler->view;
    $relationships = array();

    // Collect all relationships, keyed by alias.
    foreach ($view->relationship as $key => $relationship) {
      $key = $relationship->alias ? $relationship->alias : $key;
      $relationships[$key] = $relationship;
    }
    while (!empty($current_handler->relationship) && !empty($relationships[$current_handler->relationship])) {
      $current_handler = $relationships[$current_handler->relationship];
      $return = $current_handler->real_field . ($return ? ":{$return}" : '');
    }
  }
  if ($complete) {
    $return .= ($return ? ':' : '') . $handler->real_field;
  }
  elseif ($pos = strrpos($handler->real_field, ':')) {

    // If we have a selector as the real_field, append this to the returned
    // relationship selector.
    $return .= ($return ? ':' : '') . substr($handler->real_field, 0, $pos);
  }
  return $return;
}