protected function ResourceFieldEntityReference::mergeEntityFromReference in RESTful 7.2
Helper function; Create an entity from a a sub-resource.
Parameters
mixed $value: The single value for the sub-request.
Return value
mixed The value to set using the wrapped property.
1 call to ResourceFieldEntityReference::mergeEntityFromReference()
- ResourceFieldEntityReference::preprocess in src/
Plugin/ resource/ Field/ ResourceFieldEntityReference.php - Massage the value to set according to the format expected by the wrapper.
File
- src/
Plugin/ resource/ Field/ ResourceFieldEntityReference.php, line 100 - Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityReference.
Class
- ResourceFieldEntityReference
- Class ResourceFieldEntityReference.
Namespace
Drupal\restful\Plugin\resource\FieldCode
protected function mergeEntityFromReference($value) {
$resource = $this
->getResource();
if (empty($resource) || empty($value['body'])) {
// Field is not defined as "resource", which means it only accepts an
// integer as a valid value.
// Or, we are passing an integer and cardinality is 1. That means that we
// are passing the ID of the referenced entity. Hence setting the new
// value to the reference field.
return $value;
}
// Get the resource data provider and make the appropriate operations.
// We need to create a RequestInterface object for the sub-request.
$resource_data_provider = DataProviderResource::init(static::subRequest($value), $resource['name'], array(
$resource['majorVersion'],
$resource['minorVersion'],
));
// We are always dealing with the single value.
$merged = $resource_data_provider
->merge(static::subRequestId($value), $value['body']);
return reset($merged);
}