/** * Static instance provider. * * Method providing static instance of as in Singleton pattern. */ public static function &singleton() { if (!isset(self::$_singleton)) { self::$_singleton = new CRM_Core_Form_Renderer(); } return self::$_singleton; }
/** * Getter function for renderer. If renderer is not set * create one and initialize it * * @return object */ public function &getRenderer() { if (!isset($this->_renderer)) { $this->_renderer = CRM_Core_Form_Renderer::singleton(); } return $this->_renderer; }
/** * Creates an array representing an element containing * the key for storing this. We allow the parent to do most of the * work, but then we add some CiviCRM specific enhancements to * make the html compliant with our css etc * * @access private * @param object An HTML_QuickForm_element object * @param bool Whether an element is required * @param string Error associated with the element * @return array */ function _elementToArray(&$element, $required, $error) { CRM_Core_Form_Renderer::updateAttributes($element, $required, $error); $el = parent::_elementToArray($element, $required, $error); // add label html if (!empty($el['label'])) { $id = $element->getAttribute('id'); if (!empty($id)) { $el['label'] = '<label for="' . $id . '">' . $el['label'] . '</label>'; } } return $el; }
/** * Renders an element Html * Called when visiting an element * * @param HTML_QuickForm_element form element being visited * @param bool Whether an element is required * @param string An error message associated with an element * @access public * @return void */ function renderElement(&$element, $required, $error) { // make sure that all elements are id'ed even in a group! CRM_Core_Form_Renderer::updateAttributes($element, $required, $error); if (!$this->_inGroup) { $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error); $this->_html .= str_replace('{element}', $element->toHtml(), $html); } elseif (!empty($this->_groupElementTemplate)) { $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate); if ($required) { $html = str_replace('<!-- BEGIN required -->', '', $html); $html = str_replace('<!-- END required -->', '', $html); } else { $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*<!-- END required -->([ \t\n\r]*)?/isU", '', $html); } $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html); } else { $this->_groupElements[] = $element->toHtml(); } }