Example #1
0
 /**
  * Create advance group of elements
  *
  * @param MoodleQuickForm_group $group Passed by reference
  * @param bool $required if input is required field
  * @param string $error error message to display
  */
 function startGroup(&$group, $required, $error)
 {
     global $OUTPUT;
     // Make sure the element has an id.
     $group->_generateId();
     // Prepend 'fgroup_' to the ID we generated.
     $groupid = 'fgroup_' . $group->getAttribute('id');
     // Update the ID.
     $group->updateAttributes(array('id' => $groupid));
     $advanced = isset($this->_advancedElements[$group->getName()]);
     $html = $OUTPUT->mform_element($group, $required, $advanced, $error, false);
     $fromtemplate = !empty($html);
     if (!$fromtemplate) {
         if (method_exists($group, 'getElementTemplateType')) {
             $html = $this->_elementTemplates[$group->getElementTemplateType()];
         } else {
             $html = $this->_elementTemplates['default'];
         }
         if (isset($this->_advancedElements[$group->getName()])) {
             $html = str_replace(' {advanced}', ' advanced', $html);
             $html = str_replace('{advancedimg}', $this->_advancedHTML, $html);
         } else {
             $html = str_replace(' {advanced}', '', $html);
             $html = str_replace('{advancedimg}', '', $html);
         }
         if (method_exists($group, 'getHelpButton')) {
             $html = str_replace('{help}', $group->getHelpButton(), $html);
         } else {
             $html = str_replace('{help}', '', $html);
         }
         $html = str_replace('{id}', $group->getAttribute('id'), $html);
         $html = str_replace('{name}', $group->getName(), $html);
         $html = str_replace('{typeclass}', 'fgroup', $html);
         $html = str_replace('{type}', 'group', $html);
         $html = str_replace('{class}', $group->getAttribute('class'), $html);
         $emptylabel = '';
         if ($group->getLabel() == '') {
             $emptylabel = 'femptylabel';
         }
         $html = str_replace('{emptylabel}', $emptylabel, $html);
     }
     $this->_templates[$group->getName()] = $html;
     // Fix for bug in tableless quickforms that didn't allow you to stop a
     // fieldset before a group of elements.
     // if the element name indicates the end of a fieldset, close the fieldset
     if (in_array($group->getName(), $this->_stopFieldsetElements) && $this->_fieldsetsOpen > 0) {
         $this->_html .= $this->_closeFieldsetTemplate;
         $this->_fieldsetsOpen--;
     }
     if (!$fromtemplate) {
         parent::startGroup($group, $required, $error);
     } else {
         $this->_html .= $html;
     }
 }