all_relationships;
*
* This variable is an array with two sub arrays with the keys 'object' and 'subject'. The array with
* key 'object' contains relationships where the project is the object, and the array with
* the key 'subject' contains relationships where the project is the subject
*/
$project = $variables['node']->project;
$all_relationships = $project->all_relationships;
$object_rels = $all_relationships['object'];
$subject_rels = $all_relationships['subject'];
if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
This
project is related to the following other projects:
$objects) {
foreach ($objects as $object) {
// link the project to it's node
$object_name = $object->record->object_project_id->name;
if (property_exists($object->record, 'nid')) {
$object_name = l($object_name, "node/" . $object->record->nid, ['attributes' => ['target' => "_blank"]]);
}
$rows[] = [
"$project->name is a \"$rel_type\" of $object_name",
];
}
}
// second add in the object relationships.
foreach ($object_rels as $rel_type => $subjects) {
foreach ($subjects as $subject) {
// link the project to it's node
$subject_name = $subject->record->subject_project_id->name;
if (property_exists($subject->record, 'nid')) {
$subject_name = l($subject_name, "node/" . $subject->record->nid, ['attributes' => ['target' => "_blank"]]);
}
$rows[] = [
"$subject_name is a \"$rel_type\" of $project->name",
];
}
}
// the $table array contains the headers and rows array as well as other
// options for controlling the display of the table. Additional
// documentation can be found here:
// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
$table = [
'header' => $headers,
'rows' => $rows,
'attributes' => [
'id' => 'tripal_project-table-relationship-subject',
'class' => 'tripal-data-table',
],
'sticky' => FALSE,
'caption' => '',
'colgroups' => [],
'empty' => '',
];
// once we have our table array structure defined, we call Drupal's theme_table()
// function to generate the table.
print theme_table($table);
}