Exemple #1
0
 /**
  * Renders an mform element from a template.
  *
  * @param HTML_QuickForm_element $element element
  * @param bool $required if input is required field
  * @param bool $advanced if input is an advanced field
  * @param string $error error message to display
  * @param bool $ingroup True if this element is rendered as part of a group
  * @return mixed string|bool
  */
 public function mform_element($element, $required, $advanced, $error, $ingroup)
 {
     $templatename = 'core_form/element-' . $element->getType();
     if ($ingroup) {
         $templatename .= "-inline";
     }
     try {
         // We call this to generate a file not found exception if there is no template.
         // We don't want to call export_for_template if there is no template.
         core\output\mustache_template_finder::get_template_filepath($templatename);
         if ($element instanceof templatable) {
             $elementcontext = $element->export_for_template($this);
             $helpbutton = '';
             if (method_exists($element, 'getHelpButton')) {
                 $helpbutton = $element->getHelpButton();
             }
             $label = $element->getLabel();
             if (method_exists($element, 'getText')) {
                 $label .= ' ' . $element->getText();
             }
             $context = array('element' => $elementcontext, 'label' => $label, 'required' => $required, 'advanced' => $advanced, 'helpbutton' => $helpbutton, 'error' => $error);
             return $this->render_from_template($templatename, $context);
         }
     } catch (Exception $e) {
         // No template for this element.
         return false;
     }
 }