You are here

protected function RestfulEntityBase::propertyValuesPreprocessReference in RESTful 7

Pre-process value for "Entity reference" field types.

Parameters

string $property_name: The property name to set.

$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::propertyValuesPreprocessReference()
RestfulEntityBase::propertyValuesPreprocess in plugins/restful/RestfulEntityBase.php
Massage the value to set according to the format expected by the wrapper.

File

plugins/restful/RestfulEntityBase.php, line 792
Contains RestfulEntityBase.

Class

RestfulEntityBase
An abstract implementation of RestfulEntityInterface.

Code

protected function propertyValuesPreprocessReference($property_name, $value, $field_info, $public_field_name) {
  if (!$value) {

    // If value is empty, return NULL, so no new entity will be created.
    return;
  }
  if ($field_info['cardinality'] != 1 && !is_array($value)) {

    // If the field is entity reference type and its cardinality larger than
    // 1 set value to an array.
    $value = explode(',', $value);
  }
  $value = $this
    ->createEntityFromReference($property_name, $value, $field_info, $public_field_name);
  return $value;
}