function relation_rules_set_endpoints in Relation 8.2
Same name and namespace in other branches
- 8 relation.rules.inc \relation_rules_set_endpoints()
- 7 relation.rules.inc \relation_rules_set_endpoints()
Endpoint property setter callback.
Parameters
$data: The relation object that we are going to modify.
$name: Name of the provided Rules variable.
$endpoint_wrappers: Array of entity wrappers that we are going to add to the relation object.
File
- ./
relation.rules.inc, line 148 - Implements the Rules module API for Relation.
Code
function relation_rules_set_endpoints(&$relation = NULL, $name = NULL, $entity_wrappers = NULL) {
// Check that we are creating a new relation. Updating existing relations
// aren't supported.
$relation_id = $relation
->id();
if (isset($relation_id) || empty($entity_wrappers)) {
return;
}
foreach ($entity_wrappers as $i => $entity_wrapper) {
$entity = $entity_wrapper
->value();
$entity_type = $entity_wrapper
->type();
$id_key = $entity_wrapper
->entityKey('id');
$bundle_key = $entity_wrapper
->entityKey('bundle');
if (isset($entity->{$id_key})) {
$relation->endpoints[Language::LANGCODE_NOT_SPECIFIED][$i] = array(
'entity_type' => $entity_wrapper
->type(),
'entity_id' => $entity->{$id_key},
'entity_bundle' => isset($entity->{$bundle_key}) ? $entity->{$bundle_key} : $entity_type,
'delta' => $i,
);
}
}
}