protected function getOptions()
{
if (!is_array($this->arguments['options']) && !$this->arguments['options'] instanceof \Traversable) {
return array();
}
$options = array();
foreach ($this->arguments['options'] as $key => $value) {
if (is_object($value)) {
if ($this->hasArgument('optionValueField')) {
$key = ObjectAccess::getPropertyPath($value, $this->arguments['optionValueField']);
if (is_object($key)) {
if (method_exists($key, '__toString')) {
$key = (string) $key;
} else {
throw new ViewHelper\Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428);
}
}
} elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
$key = $this->persistenceManager->getIdentifierByObject($value);
} elseif (method_exists($value, '__toString')) {
$key = (string) $value;
} else {
throw new ViewHelper\Exception('No identifying value for object of class "' . get_class($value) . '" found.', 1247826696);
}
if ($this->hasArgument('optionLabelField')) {
$value = ObjectAccess::getPropertyPath($value, $this->arguments['optionLabelField']);
if (is_object($value)) {
if (method_exists($value, '__toString')) {
$value = (string) $value;
} else {
throw new ViewHelper\Exception('Label value for object of class "' . get_class($value) . '" was an object without a __toString() method.', 1247827553);
}
}
} elseif (method_exists($value, '__toString')) {
$value = (string) $value;
} elseif ($this->persistenceManager->getIdentifierByObject($value) !== null) {
$value = $this->persistenceManager->getIdentifierByObject($value);
}
}
if ($this->hasArgument('translate')) {
$value = $this->getTranslatedLabel($key, $value);
}
$options[$key] = $value;
}
if ($this->arguments['sortByOptionLabel']) {
asort($options);
}
return $options;
}