You are here

function location_location_from_node_context in Location 7.3

Same name and namespace in other branches
  1. 6.3 plugins/relationships/location_from_node.inc \location_location_from_node_context()
  2. 7.5 plugins/relationships/location_from_node.inc \location_location_from_node_context()
  3. 7.4 plugins/relationships/location_from_node.inc \location_location_from_node_context()

Return a new location context based on a node context.

This does all the magic from the relationship settings to select if we're dealing with a location_node field or a location_cck field, what field offset to use, etc.

Parameters

object $context: The node context we're creating a relationship context out of.

array $conf: The configuration settings for this relationship.

Return value

object Either a valid location context object based on the given node and the currently active configuration settings, an empty context object (e.g. for configuration in the Panels admin UI), or NULL in case the given node context does not contain valid location data matching the current relationship settings.

1 string reference to 'location_location_from_node_context'
location_location_from_node_ctools_relationships in plugins/relationships/location_from_node.inc
Implement hook_[relationship_name]_ctools_relationships().

File

plugins/relationships/location_from_node.inc, line 47
Plugin to provide an relationship handler for location data from node.

Code

function location_location_from_node_context($context, $conf) {

  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data)) {
    $new_context = ctools_context_create_empty('location', NULL);
  }

  // Grab the right location data based on the relationship settings.
  if (isset($conf['location_type'])) {
    if ($conf['location_type'] == 'location_node' && isset($context->data->locations)) {
      $location_offset = isset($conf['location_node_offset']) ? $conf['location_node_offset'] : 0;
      $location = $context->data->locations[$location_offset];
    }
    elseif ($conf['location_type'] == 'location_cck' && isset($conf['location_cck_field_name'])) {
      $field_name = $conf['location_cck_field_name'];
      $field_offset = isset($conf['location_cck_field_offset']) ? $conf['location_cck_field_offset'] : 0;
      if (isset($context->data->{$field_name}[LANGUAGE_NONE][$field_offset]['lid'])) {
        $location = $context->data->{$field_name}[LANGUAGE_NONE][$field_offset];
      }
    }
  }
  if (!empty($location)) {
    $location['nid'] = $context->data->nid;
    $new_context = ctools_context_create('location', $location);
  }
  if (!empty($new_context)) {
    return $new_context;
  }
}