private function extractLabels($choices, array &$labels) { foreach ($choices as $i => $choice) { if ((is_array($choice) || $choice instanceof \Traversable) && !$choice instanceof ItemInterface) { $labels[$i] = array(); $this->extractLabels($choice, $labels[$i]); } elseif ($this->labelPath) { //$labels[$i] = $this->labelPath->getValue($choice); if (version_compare(Kernel::VERSION, '2.1') <= 0) { $labelValue = $this->labelPath->getValue($choice); } else { $propertyAccessor = PropertyAccess::getPropertyAccessor(); $labelValue = $propertyAccessor->getValue($choice, $this->labelPath); } $labels[$i] = str_repeat('-', $choice->getLevel()) . ' ' . $labelValue; } elseif (method_exists($choice, '__toString')) { $labels[$i] = (string) $choice; } else { throw new StringCastException('A "__toString()" method was not found on the objects of type "' . get_class($choice) . '" passed to the choice field. To read a custom getter instead, set the argument $labelPath to the desired property path.'); } } }