public function renderInitcmsFieldAsString($template, $object, FormView $formView, $translationDomain = null)
{
/** @var $fieldDescription \Sonata\DoctrineORMAdminBundle\Admin\FieldDescription */
$fieldDescription = $formView->vars['sonata_admin']['field_description'];
$value = '';
switch ($fieldDescription->getType()) {
case 'hidden':
$value = $fieldDescription->getValue($object);
break;
case 'boolean':
if ($fieldDescription->getValue($object)) {
$value = 'positive';
} else {
$value = 'negative';
}
break;
case 'string':
case 'text':
$value = $fieldDescription->getValue($object);
break;
case 'choice':
case 'sonata_type_translatable_choice':
case 'networking_type_autocomplete':
case 'networking_type_iconradio':
case 'entity':
$choices = $formView->vars['choices'];
$preferredChoices = $formView->vars['preferred_choices'];
$choices = array_merge($choices, $preferredChoices);
$selected = $fieldDescription->getValue($object);
if (is_object($selected)) {
$selected = (string) $selected->getId();
}
foreach ($choices as $choice) {
/** @var $choice \Symfony\Component\Form\Extension\Core\View\ChoiceView */
if ($choice->value == $selected) {
$value = $choice->label;
}
}
break;
case 'date':
/** @var $date \DateTime */
$date = $fieldDescription->getValue($object);
if ($date) {
$value = $date->format('d.m.Y');
} else {
$value = '';
}
break;
case 'datetime':
/** @var $date \DateTime */
$date = $fieldDescription->getValue($object);
if ($date) {
$value = $date->format('d.m.Y H:i');
} else {
$value = '';
}
break;
case 'sonata_type_model_hidden':
$value = $fieldDescription->getValue($object);
break;
default:
var_dump($fieldDescription->getType());
break;
}
if ($displayMethod = $fieldDescription->getOption('display_method')) {
$value = $this->getFieldValue($object, $fieldDescription->getFieldName(), $displayMethod);
}
$options = array('page' => $object, 'field' => $fieldDescription->getName(), 'value' => $this->getService('translator')->trans($value, array(), $translationDomain), 'translation_domain' => $translationDomain);
return $this->getService('templating')->render($template, $options);
}