public function ServicesClientFieldReader::read in Services Client 7.2
Read property from entity.
Parameters
object $entity: Entity that is being read.
Return value
array
Overrides ServicesClientMappingReaderInterface::read
File
- include/
mapping.inc, line 416
Class
- ServicesClientFieldReader
- Reads data from drupal field.
Code
public function read($entity) {
$value = new ServicesClientMappingValue();
$items = isset($entity->{$this->config['field']}[$this->config['language']]) ? $entity->{$this->config['field']}[$this->config['language']] : NULL;
if (!empty($items)) {
// We read only single value
if ($this->config['all_values'] == FALSE) {
$items = array(
reset($items),
);
}
$out = array();
foreach ($items as $item) {
if (isset($item[$this->config['property']])) {
$out[] = $item[$this->config['property']];
}
}
if (!empty($out)) {
$value
->setValue($out);
}
else {
$value
->setEmpty();
}
}
else {
$value
->setEmpty();
}
return $value;
}