Beispiel #1
0
 public function getForm($template, $formInstance = null, $content = null)
 {
     if ($formInstance == null) {
         $formInstance = new Digitalus_Content_Form();
     }
     $view = $formInstance->getView();
     $controls = $this->getControls($template);
     if ($controls) {
         foreach ($controls as $control) {
             $attribs = $control->attributes();
             $id = (string) $attribs['id'];
             if (!in_array($id, $this->_forbiddenElements)) {
                 $type = (string) $attribs['type'];
                 if (isset($attribs['required'])) {
                     $required = true;
                     unset($attribs['required']);
                 } else {
                     $required = false;
                 }
                 if (isset($attribs['label'])) {
                     $label = $view->getTranslation((string) $attribs['label']);
                     unset($attribs['label']);
                 } else {
                     $label = $view->getTranslation(ucwords(str_replace('_', ' ', $id)));
                 }
                 $control = $formInstance->createElement($type, $id, array('label' => $label, 'required' => $required, 'decorators' => array('ViewHelper')));
                 $control->setAttrib('rel', isset($attribs['group']) ? (string) $attribs['group'] : 'main');
                 foreach ($attribs as $attribute => $value) {
                     $control->setAttrib($attribute, $value);
                 }
                 if (isset($content[$id])) {
                     $control->setValue($content['id']);
                 }
                 $formInstance->addElement($control);
                 // set the display group
                 // $displayGroup = (isset($attribs['group']))? (string)$attribs['group'] : 'main';
                 // $formInstance->addDisplayGroup(array($control), $displayGroup);
             }
         }
     }
     return $formInstance;
 }
Beispiel #2
0
 public function getForm($template, $formInstance = null, $content = null)
 {
     if ($formInstance == null) {
         $formInstance = new Digitalus_Content_Form();
     }
     $view = $formInstance->getView();
     $controls = $this->getControls($template);
     if ($controls) {
         foreach ($controls as $control) {
             $attribs = $control->attributes();
             $id = (string) $attribs['id'];
             $type = (string) $attribs['type'];
             if (isset($attribs['required'])) {
                 $required = true;
                 unset($attribs['required']);
             } else {
                 $required = false;
             }
             if (isset($attribs['label'])) {
                 $label = (string) $attribs['label'];
                 unset($attribs['label']);
             } else {
                 $label = $view->getTranslation($id);
                 $label = ucwords(str_replace('_', ' ', $label));
             }
             $control = $formInstance->createElement($type, $id, $attribs);
             $control->setLabel($label);
             $control->setRequired($required);
             $control->setAttrib('rel', isset($attribs['group']) ? (string) $attribs['group'] : 'main');
             if (isset($content[$id])) {
                 $control->setValue($content['id']);
             }
             $formInstance->addElement($control);
             // set the display group
             // $displayGroup = (isset($attribs['group']))? (string)$attribs['group'] : 'main';
             // $formInstance->addDisplayGroup(array($control), $displayGroup);
         }
     }
     return $formInstance;
 }