create() public static method

public static create ( array $settings = [] ) : FluidTYPO3\Flux\Form\FieldInterface
$settings array
return FluidTYPO3\Flux\Form\FieldInterface
 /**
  * @param array $settings
  * @return FormInterface
  */
 public static function create(array $settings = array())
 {
     /** @var ObjectManagerInterface $objectManager */
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $className = get_called_class();
     /** @var FormInterface $object */
     $object = $objectManager->get($className);
     foreach ($settings as $settingName => $settingValue) {
         $setterMethodName = ObjectAccess::buildSetterMethodName($settingName);
         if (TRUE === method_exists($object, $setterMethodName)) {
             ObjectAccess::setProperty($object, $settingName, $settingValue);
         }
     }
     if (TRUE === $object instanceof FieldContainerInterface && TRUE === isset($settings['fields'])) {
         foreach ($settings['fields'] as $fieldName => $fieldSettings) {
             if (FALSE === isset($fieldSettings['name'])) {
                 $fieldSettings['name'] = $fieldName;
             }
             $field = AbstractFormField::create($fieldSettings);
             $object->add($field);
         }
     }
     return $object;
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function canCreateSectionUsingShortcutMethod()
 {
     $definition = array('name' => 'test', 'label' => 'Test section', 'type' => 'Section');
     $section = AbstractFormField::create($definition);
     $this->assertInstanceOf('FluidTYPO3\\Flux\\Form\\Container\\Section', $section);
     $this->assertSame($definition['name'], $section->getName());
 }
 /**
  * @param string $class
  * @param string $table
  * @return Form
  */
 public function generateFormInstanceFromClassName($class, $table)
 {
     $labelFields = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Label', NULL);
     $extensionName = $this->getExtensionNameFromModelClassName($class);
     $values = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Form\\Field', NULL);
     $sheets = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Form\\Sheet', NULL);
     $labels = TRUE === is_array($labelFields) ? array_keys($labelFields) : array(key($values));
     $hasVisibilityToggle = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Control\\Hide');
     $hasDeleteToggle = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Control\\Delete');
     $hasStartTimeToggle = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Control\\StartTime');
     $hasEndTimeToggle = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Control\\EndTime');
     $hasFrontendGroupToggle = AnnotationUtility::getAnnotationValueFromClass($class, 'Flux\\Control\\FrontendUserGroup');
     $form = Form::create();
     $form->setName($table);
     $form->setExtensionName($extensionName);
     $form->setOption('labels', $labels);
     $form->setOption('delete', $hasDeleteToggle);
     $form->setOption('hide', $hasVisibilityToggle);
     $form->setOption('start', $hasStartTimeToggle);
     $form->setOption('end', $hasEndTimeToggle);
     $form->setOption('frontendUserGroup', $hasFrontendGroupToggle);
     $fields = array();
     foreach ($sheets as $propertyName => $sheetAnnotation) {
         $sheetName = $sheetAnnotation['type'];
         if (FALSE === isset($fields[$sheetName])) {
             $fields[$sheetName] = array();
         }
         array_push($fields[$sheetName], $propertyName);
     }
     foreach ($fields as $sheetName => $propertyNames) {
         $form->remove($sheetName);
         $sheets[$sheetName] = $form->createContainer('Sheet', $sheetName);
         foreach ($propertyNames as $propertyName) {
             $settings = $values[$propertyName];
             if (TRUE === isset($settings['type'])) {
                 $field = AbstractFormField::create($settings);
                 $sheets[$sheetName]->add($field);
             }
         }
     }
     return $form;
 }