Example #1
0
 /**
  * Renders a raw fieldset of a F0FForm and returns the corresponding HTML
  *
  * @param   stdClass  &$fieldset   The fieldset to render
  * @param   F0FForm   &$form       The form to render
  * @param   F0FModel  $model       The model providing our data
  * @param   F0FInput  $input       The input object
  * @param   string    $formType    The form type e.g. 'edit' or 'read'
  * @param   boolean   $showHeader  Should I render the fieldset's header?
  *
  * @return  string    The HTML rendering of the fieldset
  */
 protected function renderFieldset(stdClass &$fieldset, F0FForm &$form, F0FModel $model, F0FInput $input, $formType, $showHeader = true)
 {
     $html = '';
     $fields = $form->getFieldset($fieldset->name);
     if (isset($fieldset->class)) {
         $class = 'class="' . $fieldset->class . '"';
     } else {
         $class = '';
     }
     $element = empty($fields) ? 'div' : 'fieldset';
     $html .= "\t" . '<' . $element . ' id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
     $isTabbedFieldset = $this->isTabFieldset($fieldset);
     if (isset($fieldset->label) && !empty($fieldset->label) && !$isTabbedFieldset) {
         $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
     }
     foreach ($fields as $field) {
         $groupClass = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
         // Auto-generate label and description if needed
         // Field label
         $title = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
         $emptylabel = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
         if (empty($title) && !$emptylabel) {
             $model->getName();
             $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
         }
         // Field description
         $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
         /**
          * The following code is backwards incompatible. Most forms don't require a description in their form
          * fields. Having to use emptydescription="1" on each one of them is an overkill. Removed.
          */
         /*
         $emptydescription   = $form->getFieldAttribute($field->fieldname, 'emptydescription', false, $field->group);
         if (empty($description) && !$emptydescription)
         {
         	$description = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_DESC');
         }
         */
         if ($formType == 'read') {
             $inputField = $field->static;
         } elseif ($formType == 'edit') {
             $inputField = $field->input;
         }
         if (empty($title)) {
             $html .= "\t\t\t" . $inputField . PHP_EOL;
             if (!empty($description) && $formType == 'edit') {
                 $html .= "\t\t\t\t" . '<span class="help-block">';
                 $html .= JText::_($description) . '</span>' . PHP_EOL;
             }
         } else {
             $html .= "\t\t\t" . '<div class="fof-row ' . $groupClass . '">' . PHP_EOL;
             $html .= $this->renderFieldsetLabel($field, $form, $title);
             $html .= "\t\t\t\t" . $inputField . PHP_EOL;
             if (!empty($description)) {
                 $html .= "\t\t\t\t" . '<span class="help-block">';
                 $html .= JText::_($description) . '</span>' . PHP_EOL;
             }
             $html .= "\t\t\t" . '</div>' . PHP_EOL;
         }
     }
     $element = empty($fields) ? 'div' : 'fieldset';
     $html .= "\t" . '</' . $element . '>' . PHP_EOL;
     return $html;
 }