/** * * @param string $className * @param ReflectionProperty|string $property * @return \PopCode\Framework\Form\FormType */ public static function getFormType($className, $property) { if (!$property instanceof ReflectionProperty) { $property = new ReflectionProperty($className, $property); } //read the form type from annotation $formType = static::$annotationReader->getPropertyAnnotation($property, 'PopCode\\Framework\\Form\\FormType'); //override formType from model method $reflection = new ReflectionClass($className); if ($reflection->implementsInterface('PopCode\\Framework\\Model\\FormConfigInterface')) { $reflection->getMethod('getFormType')->invoke(new $className(), $property->getName(), $formType); } if (!$formType) { return; } //Auto group ? if ($formType->getGroup() !== false) { $formType->setGroup(true); } //Auto label ? if ($formType->getLabel() === null) { //translate label here ? $formType->setLabel(Helper::stringToLabel($property->getName())); } //themings @todo moove this part with template render $formType->setLabelAttrs(array('class' => 'control-label')); //merge the attrs with predefined data to get the form-control class if ($formType->getType() !== 'radio' && $formType->getType() !== 'checkbox') { $attrs = $formType->getAttrs(); $formType->setAttrs(array_merge(array('class' => 'form-control'), $attrs)); } if ($formType->getType() != 'radio' && $formType->getType() != 'checkbox') { $attrs = $formType->getAttrs(); $formType->setAttrs(array_merge(array('class' => 'form-control'), $attrs)); } //set the classes on container to form-group $classes = $formType->getClasses(); $classes = trim(preg_replace('/form-group/', '', $classes) . ' form-group'); $formType->setClasses($classes); return $formType; }