Short version:


When using a relationship that is of type "content type<->relationship", I get an ajax error. Running the error to ground shows that error here:
template: "relation_wizard_ui.module"
function: "_relation_wizard_ui_datatable_ajax"
statement: $rows = array_merge($rows, $entity_manager->getRows($entity_type, $iDisplayStart, $iDisplayLength, $bundles, $sSearch));
error: Call to a member function getRows() on a non-object, relation_wizard_ui.module, line 732

Really long version:


Conditions:
  1. I have content types Vehicle, Airport, Zone
  2. I have a relationship between Airport<->Zone - directional, transitive, unique, 2 arity. This relationship has a machine name of "airport_zone".
  3. I have relationship between Vehicle (content type) and Airport<->Zone (relationship) - directional, transitive, unique, 2 arity. This relationship has a machine name of "vehicle_airport2zone".
  4. I have entered in content for Vehicle, Airport, Zones
  5. I have created Airport<->Zone relationships with the relationship wizard ui without issues

When I try to create a Vehicle<->Airport2Zone relationship with the relationship wizard ui, I get

DataTables warning (table id = 'Datatables_Table_0'): DataTable warning: JSON data from server could not be parsed.  This is caused by a JSON formatting error.

Checking the ajax call in relation-wizard-ui.js, I see that the calls are:
Vehicle<->Zone:
/relation_wizard_ui/datatable_ajax?rel_type=airport_zone&rel_direction=target

Vehicle<->Airport2Zone:
/relation_wizard_ui/datatable_ajax?rel_type=vehicle_airport2zone&rel_direction=target

Running the code by hand yields the following (all of the variables below are from inside template "relation_wizard_ui.module", function "_relation_wizard_ui_datatable_ajax":

// THIS WORKS
Passing in:
  $type = 'airport_zone'; // this is a "content type<->content type" relationship
  $direction = 'target';
  $iDisplayStart = NULL;
  $iDisplayLength = 5;
  $sSearch = NULL;

$relation_type
--------------------------------------------
stdClass::__set_state(array(
   'relation_type' => 'airport_zone',
   'label' => 'Airport <-> Zone',
   'reverse_label' => 'Airport <-> Zone',
   'directional' => '1',
   'transitive' => '1',
   'r_unique' => '1',
   'min_arity' => '2',
   'max_arity' => '2',
   'table' => 'relation_type',
   'type' => 'Normal',
   'export_type' => 1,
   'source_bundles' => 
  array (
    0 => 'node:airport_content',
  ),
   'target_bundles' => 
  array (
    0 => 'node:zone_content',
  ),
   'bundles_loaded' => true,
))

$entity_bundles
--------------------------------------------
array (
  'node' => 
  array (
    0 => 'zone_content',
  ),
)


debug($entity_manager->getRows($entity_type, $iDisplayStart, $iDisplayLength, $bundles, $sSearch));
--------------------------------------------
array (
  0 => 
  array (
    0 => 'Zone 1',
    1 => 'node',
    2 => 40,
  ),
  1 => 
  array (
    0 => 'Zone 2',
    1 => 'node',
    2 => 41,
  ),
  2 => 
  array (
    0 => 'Zone 3',
    1 => 'node',
    2 => 42,
  ),
  3 => 
  array (
    0 => 'Zone 4',
    1 => 'node',
    2 => 43,
  ),
  4 => 
  array (
    0 => 'Zone 5',
    1 => 'node',
    2 => 44,
  ),
)

When looking at individual elements of above debug:
$entity_type = 'node'
$iDisplayStart = NULL
$iDisplayLength = 5
$bundles = array (  0 => 'zone_content', )
$sSearch = NULL
// THIS DOES NOT WORK
Passing in:
  $type = 'vehicle_airport2zone'; // this is a "content type<->relationship" relationship
  $direction = 'target';
  $iDisplayStart = NULL;
  $iDisplayLength = 5;
  $sSearch = NULL;

$relation_type
--------------------------------------------
stdClass::__set_state(array(
   'relation_type' => 'vehicle_airport2zone',
   'label' => 'Vehicle<->Airport_Zone',
   'reverse_label' => 'Vehicle<->Airport_Zone',
   'directional' => '1',
   'transitive' => '1',
   'r_unique' => '1',
   'min_arity' => '2',
   'max_arity' => '2',
   'table' => 'relation_type',
   'type' => 'Normal',
   'export_type' => 1,
   'source_bundles' => 
  array (
    0 => 'node:vehicle_content',
  ),
   'target_bundles' => 
  array (
    0 => 'relation:vehicle_airport_zone',
  ),
   'bundles_loaded' => true,
))


$entity_bundles
--------------------------------------------
array (
  'relation' => 
  array (
    0 => 'vehicle_airport_zone',
  ),
)


debug($entity_manager->getRows($entity_type, $iDisplayStart, $iDisplayLength, $bundles, $sSearch));
--------------------------------------------
ERROR: Call to a member function getRows() on a non-object, relation_wizard_ui.module, line 732

When looking at individual elements:
$entity_type = 'relation'
$iDisplayStart = NULL
$iDisplayLength = 5
$bundles = array (  0 => 'vehicle_airport_zone', )
$sSearch = NULL

Comments

jmoyles’s picture

Status: Active » Needs review

To work around this issue, made the following changes:

To allow the "relation" entity_type to work in the relation entity factory builder, changed ./includes/RelationEntityFactory.inc as follows:

    switch($entity_type) {
      case 'node':
      case 'relation':
        return new NodeRelationEndpointEntity();
      case 'user':
        return new UserRelationEndpointEntity();
    }

To allow a user friendly name for a relation instead of the relation ID, changed ./relation_wizard_ui.module as follows (NOTE: this is a quick and dirty hack - only tested for both endpoints as nodes):

function _relation_wizard_ui_get_entity_label($entity_type, $entity) {
  if ($entity_type == 'relation') {
  	// Relations don't have labels in and of themselves, so use the endpoints to build a label
	$entity_source_type = $entity->endpoints['und'][0]['entity_type'];
	$entity_source_id = $entity->endpoints['und'][0]['entity_id'];
	$entity_destination_type = $entity->endpoints['und'][1]['entity_type'];
	$entity_destination_id = $entity->endpoints['und'][1]['entity_id'];
	
	$sourceEntity = entity_load($entity_source_type, array($entity_source_id));
	$destinationEntity = entity_load($entity_destination_type, array($entity_destination_id));
	
	return array_shift($sourceEntity)->title . ':' . array_shift($destinationEntity)->title;
  }
  else {
    // Not a relationship entity_type
    return entity_label($entity_type, $entity);
  }
}

To allow a relation to display properly on the listing page, changed ./relation_wizard_ui.module as follows (NOTE: this is a quick and dirty hack - only tested for both endpoints as nodes):

function _relation_wizard_ui_get_table($entity, $entity_type, $direct = TRUE) {
  ...
  $rows[] = array(
    l(_relation_wizard_ui_get_entity_label($endpoint['entity_type'], $endpoint_entity), $endpoint_path['path']),
    $endpoint['entity_type'] . ' (' . $endpoint_bundle . ')',
    $ops,
  );
  ...
}
jmoyles’s picture

Status: Needs review » Active

Changed status as per http://drupal.org/node/156119 guidelines.