protected function RestfulEntityBase::createEntityFromReference in RESTful 7
Helper function; Create an entity from a a sub-resource.
Parameters
string $property_name: The property name to set.
mixed $value: The value passed in the request.
array $field_info: The field info array.
string $public_field_name: The name of the public field to set.
Return value
mixed The value to set using the wrapped property.
1 call to RestfulEntityBase::createEntityFromReference()
- RestfulEntityBase::propertyValuesPreprocessReference in plugins/
restful/ RestfulEntityBase.php - Pre-process value for "Entity reference" field types.
File
- plugins/
restful/ RestfulEntityBase.php, line 824 - Contains RestfulEntityBase.
Class
- RestfulEntityBase
- An abstract implementation of RestfulEntityInterface.
Code
protected function createEntityFromReference($property_name, $value, $field_info, $public_field_name) {
$public_fields = $this
->getPublicFields();
if (empty($public_fields[$public_field_name]['resource'])) {
// Field is not defined as "resource", which means it only accepts an
// integer as a valid value.
return $value;
}
if ($field_info['cardinality'] == 1 && !is_array($value)) {
return $value;
}
// In case we have multiple bundles, we opt for the first one.
$resource = reset($public_fields[$public_field_name]['resource']);
$handler = restful_get_restful_handler($resource['name'], $resource['major_version'], $resource['minor_version']);
return $this
->createOrUpdateSubResourceItems($handler, $value, $field_info);
}