Пример #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;
     }
 }
Пример #2
0
 /**
  * Update the attributes of this element and add a few CiviCRM
  * based attributes so we can style this form element better
  *
  *
  * @param HTML_QuickForm_element $element
  * @param bool $required
  *   Whether an element is required.
  * @param string $error
  *   Error associated with the element.
  *
  */
 public static function updateAttributes(&$element, $required, $error)
 {
     // lets create an id for all input elements, so we can generate nice label tags
     // to make it nice and clean, we'll just use the elementName if it is non null
     $attributes = array();
     if (!$element->getAttribute('id')) {
         $name = $element->getAttribute('name');
         if ($name) {
             $attributes['id'] = str_replace(array(']', '['), array('', '_'), $name);
         }
     }
     $class = $element->getAttribute('class');
     $type = $element->getType();
     if (!$class) {
         if ($type == 'text') {
             $size = $element->getAttribute('size');
             if (!empty($size)) {
                 $class = CRM_Utils_Array::value($size, self::$_sizeMapper);
             }
         }
     }
     if ($type == 'select' && $element->getAttribute('multiple')) {
         $type = 'multiselect';
     }
     // Add widget-specific class
     if (!$class || strpos($class, 'crm-form-') === FALSE) {
         $class = ($class ? "{$class} " : '') . 'crm-form-' . $type;
     } elseif (strpos($class, 'crm-form-entityref') !== FALSE) {
         self::preProcessEntityRef($element);
     } elseif (strpos($class, 'crm-form-contact-reference') !== FALSE) {
         self::preprocessContactReference($element);
     }
     if ($required) {
         $class .= ' required';
     }
     if ($error) {
         $class .= ' error';
     }
     $attributes['class'] = $class;
     $element->updateAttributes($attributes);
 }
Пример #3
0
 /**
  * エラー項目の背景色を設定する
  * (QuickFormの項目に対して、背景色を設定する)
  * @access public
  * @param HTML_QuickForm_element $element エラー項目
  */
 private function _setErrorAttribute(&$element)
 {
     if ('group' == $element->getType()) {
         $elements = $element->getElements();
         foreach ($elements as $value) {
             $this->_setErrorAttribute($value);
         }
     } else {
         $attr = $element->getAttributes();
         $attr['style'] = S4_ERROR_COLUMN_COLOR;
         $element->setAttributes($attr);
     }
 }
Пример #4
0
 /**
  * Returns the CSS id attribute that will be assigned by moodleform later to this element
  * @param stdClass $item
  * @param HTML_QuickForm_element $element
  */
 protected function guess_element_id($item, $element)
 {
     if (!($id = $element->getAttribute('id'))) {
         $attributes = $element->getAttributes();
         $id = $attributes['id'] = 'feedback_item_' . $item->id;
         $element->setAttributes($attributes);
     }
     if ($element->getType() === 'group') {
         return 'fgroup_' . $id;
     }
     return 'fitem_' . $id;
 }