Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function buildField($key)
- {
- if (!$this->has($key)) return '';
- $field = $this->fields[$key];
- $type = $field['type'];
- $attributes = isset($field['attributes']) ? $field['attributes'] : array();
- $attributes['name'] = $this->fixRadioName($key);
- if (!isset($attributes['id'])) {
- $attributes['id'] = 'usermeta-'.$key;
- }
- $attributes['value'] = isset($attributes['value']) ? $attributes['value'] : '';
- if (in_array($type, array('text', 'textarea', 'select'))) {
- $attributes['value'] = set_value($key, $attributes['value']);
- if ($this->hasData($key)) {
- $attributes['value'] = $this->data[$key];
- }
- }
- if ($type == 'checkbox' || $type == 'radio') {
- if ($this->hasData($attributes['name'])) {
- if ((string) $this->data[$attributes['name']] == (string) $attributes['value']) {
- $attributes['checked'] = 'checked';
- }
- } elseif (set_checkbox($attributes['name'], $attributes['value']) != '') {
- $attributes['checked'] = 'checked';
- }
- }
- $id = $attributes['id'];
- $value = '';
- if ($type == 'textarea' || $type == 'select') {
- $value = $attributes['value'];
- unset($attributes['value']);
- }
- $label = !empty($field['label']) ? $field['label'] : $this->translator->trans('userfields.'.$attributes['name']);
- $multiples = !empty($field['multiple']) ? $field['multiple'] : $this->translator->trans('multiple');
- if ($multiples == "true"){
- $multiple = "multiple";
- }
- else {
- $multiple = "";
- }
- if ($type == 'select' && isset($attributes['options'])) {
- unset($attributes['options']);
- }
- $attributes = $this->buildAttributes($attributes);
- $html = $this->contentBefore($key);
- switch ($type) {
- case 'text':
- $html .= "<label for=\"{$id}\">{$label}</label>";
- $html .= "<input type=\"text\"{$attributes}>";
- break;
- case 'textarea':
- $html .= "<label for=\"{$id}\">{$label}</label>";
- $html .= "<textarea{$attributes}>{$value}</textarea>";
- break;
- case 'select':
- $html .= "<label for=\"{$id}\">{$label}</label>";
- $html .= "<select{$attributes} {$multiple}>";
- $html .= $this->buildSelectOptions($key);
- $html .= "</select>";
- break;
- case 'checkbox':
- $html .= "<label for=\"{$id}\">";
- $html .= "<input type=\"checkbox\"{$attributes}>";
- $html .= $label;
- $html .= "</label>";
- break;
- case 'radio':
- $html .= "<label for=\"{$id}\">";
- $html .= "<input type=\"radio\"{$attributes}>";
- $html .= $label;
- $html .= "</label>";
- break;
- }
- $html .= $this->contentAfter($key);
- return $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement