protected function RestfulEntityBase::getTargetTypeFromEntityReference in RESTful 7
Get the "target_type" property from an field or property reference.
Parameters
\EntityMetadataWrapper $wrapper: The wrapped property.
$property: The public field name.
Return value
string The target type of the referenced entity.
Throws
1 call to RestfulEntityBase::getTargetTypeFromEntityReference()
- RestfulEntityBase::getValueFromResource in plugins/
restful/ RestfulEntityBase.php - Get value from an entity reference field with "resource" property.
File
- plugins/
restful/ RestfulEntityBase.php, line 465 - Contains RestfulEntityBase.
Class
- RestfulEntityBase
- An abstract implementation of RestfulEntityInterface.
Code
protected function getTargetTypeFromEntityReference(\EntityMetadataWrapper $wrapper, $property) {
$params = array(
'@property' => $property,
);
if ($field = field_info_field($property)) {
if ($field['type'] == 'entityreference') {
return $field['settings']['target_type'];
}
elseif ($field['type'] == 'taxonomy_term_reference') {
return 'taxonomy_term';
}
elseif ($field['type'] == 'field_collection') {
return 'field_collection_item';
}
elseif ($field['type'] == 'commerce_product_reference') {
return 'commerce_product';
}
elseif ($field['type'] == 'commerce_line_item_reference') {
return 'commerce_line_item';
}
elseif ($field['type'] == 'node_reference') {
return 'node';
}
throw new \RestfulException(format_string('Field @property is not an entity reference or taxonomy reference field.', $params));
}
else {
// This is a property referencing another entity (e.g. the "uid" on the
// node object).
$info = $wrapper
->info();
if ($this
->getEntityInfo($info['type'])) {
return $info['type'];
}
throw new \RestfulException(format_string('Property @property is not defined as reference in the EntityMetadataWrapper definition.', $params));
}
}