/** * Helper method for renderElement * * @param HTML_QuickForm_element $element * @param bool Whether an element is required * @param string $required Error message associated with the element * @param string $error Label for ID * @access private * @see renderElement() * @return string Html for element */ private function _prepareTemplate(HTML_QuickForm_element $element, $required, $error) { $name = $element->getName(); $label = $element->getLabel(); $labelForId = $element->getAttribute('id'); $icon = $element->getIconToHtml(); if (is_array($label)) { $nameLabel = array_shift($label); } else { $nameLabel = $label; } $labelFor = !empty($labelForId) ? 'for="' . $labelForId . '"' : 'for="' . $element->getName() . '"'; if (isset($this->_templates[$name])) { // Custom template $html = str_replace('{label}', $nameLabel, $this->_templates[$name]); } else { $customElementTemplate = $this->getCustomElementTemplate(); if (empty($customElementTemplate)) { if (method_exists($element, 'getTemplate')) { $template = $element->getTemplate($this->getForm()->getLayout()); } else { $template = $this->getForm()->getDefaultElementTemplate(); } } else { $template = $customElementTemplate; } $html = str_replace('{label}', $nameLabel, $template); } $html = str_replace('{label-for}', $labelFor, $html); $html = str_replace('{icon}', $icon, $html); 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); } if (isset($error)) { $html = str_replace('{error}', $error, $html); $html = str_replace('{error_class}', 'error has-error', $html); $html = str_replace('<!-- BEGIN error -->', '', $html); $html = str_replace('<!-- END error -->', '', $html); } else { $html = str_replace('{error_class}', '', $html); $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->.*<!-- END error -->([ \t\n\r]*)?/isU", '', $html); } if (is_array($label)) { foreach ($label as $key => $text) { $key = is_int($key) ? $key + 2 : $key; $html = str_replace("{label_{$key}}", $text, $html); $html = str_replace("<!-- BEGIN label_{$key} -->", '', $html); $html = str_replace("<!-- END label_{$key} -->", '', $html); } } if (strpos($html, '{label_')) { $html = preg_replace('/\\s*<!-- BEGIN label_(\\S+) -->.*<!-- END label_\\1 -->\\s*/is', '', $html); } return $html; }
/** * 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; }
/** * @param array $el * @param HTML_QuickForm_element $field */ public function addOptionsEditLink(&$el, $field) { if (CRM_Core_Permission::check('administer CiviCRM')) { // NOTE: $path is used on the client-side to know which option lists need rebuilding, // that's why we need that bit of data both in the link and in the form element $path = $field->getAttribute('data-option-edit-path'); // NOTE: If we ever needed to support arguments in this link other than reset=1 we could split $path here if it contains a ? $url = CRM_Utils_System::url($path, 'reset=1'); $el['html'] .= ' <a href="' . $url . '" class="crm-option-edit-link medium-popup crm-hover-button" target="_blank" title="' . ts('Edit Options') . '" data-option-edit-path="' . $path . '"><span class="icon ui-icon-wrench"></span></a>'; } }
/** * @param array $el * @param HTML_QuickForm_element $field */ function addOptionsEditLink(&$el, $field) { if (CRM_Core_Permission::check('administer CiviCRM')) { $el['html'] .= ' <a href="#" class="crm-edit-optionvalue-link crm-hover-button" title="' . ts('Edit Options') . '" data-option-group-url="' . $field->getAttribute('data-option-group-url') . '"><span class="icon edit-icon"></span></a>'; } }