public function ResourceFieldEntityFile::preprocess in RESTful 7.2
Massage the value to set according to the format expected by the wrapper.
Parameters
mixed $value: The value passed in the request.
Return value
mixed The value to set using the wrapped property.
Overrides ResourceFieldEntity::preprocess
File
- src/
Plugin/ resource/ Field/ ResourceFieldEntityFile.php, line 17 - Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityFile
Class
Namespace
Drupal\restful\Plugin\resource\FieldCode
public function preprocess($value) {
$field_info = field_info_field($this
->getProperty());
if ($field_info['cardinality'] == 1) {
// Single value.
return array(
'fid' => $value,
'display' => TRUE,
);
}
$value = is_array($value) ? $value : explode(',', $value);
$return = array();
foreach ($value as $delta => $single_value) {
$return[$delta] = array(
'fid' => $single_value,
'display' => TRUE,
);
}
return $return;
}