1: <?php
2:
3: 4: 5:
6: class Quform_Element_Group extends Quform_Element_Container
7: {
8: 9: 10: 11: 12: 13:
14: public function render(array $context = array())
15: {
16: $context = $this->prepareContext($context);
17: $output = '';
18:
19: if ($this->isVisible()) {
20: $output .= sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getContainerClasses())));
21: $output .= '<div class="quform-spacer">';
22: $output .= $this->getTitleDescriptionHtml();
23: $output .= '<div class="quform-child-elements">';
24:
25: foreach ($this->elements as $key => $element) {
26: $output .= $element->render($context);
27: }
28:
29: $output .= '</div></div></div>';
30: } else {
31: foreach ($this->getRecursiveIterator() as $element) {
32: if ( ! $element instanceof Quform_Element_Field) {
33: continue;
34: }
35:
36: if ($element->config('dynamicDefaultValue') && Quform::isNonEmptyString($element->config('dynamicKey'))) {
37: $output .= Quform::getHtmlTag('input', array(
38: 'type' => 'hidden',
39: 'name' => $element->getFullyQualifiedName(),
40: 'value' => $element->getValue()
41: ));
42: }
43: }
44: }
45:
46: return $output;
47: }
48:
49: 50: 51: 52: 53:
54: protected function getContainerClasses()
55: {
56: $classes = array(
57: 'quform-element',
58: 'quform-element-group',
59: sprintf('quform-element-%s', $this->getIdentifier()),
60: 'quform-cf',
61: sprintf('quform-group-style-%s', $this->config('groupStyle'))
62: );
63:
64: if (Quform::isNonEmptyString($this->config('customElementClass'))) {
65: $classes[] = $this->config('customElementClass');
66: }
67:
68: $classes = apply_filters('quform_container_classes', $classes, $this);
69: $classes = apply_filters('quform_container_classes_' . $this->getIdentifier(), $classes, $this);
70:
71: return $classes;
72: }
73:
74: 75: 76: 77: 78:
79: public function getLabel()
80: {
81: return apply_filters('quform_group_label_' . $this->getIdentifier(), $this->config('label'), $this, $this->getForm());
82: }
83:
84: 85: 86: 87: 88: 89:
90: protected function renderCss(array $context = array())
91: {
92: $css = '';
93:
94: if ($this->config('groupStyle') == 'bordered' && ($this->config('borderColor') || $this->config('backgroundColor'))) {
95: $css .= sprintf('.quform .quform-group-style-bordered.quform-element-%1$s > .quform-spacer > .quform-child-elements,
96: .quform .quform-group-style-bordered.quform-page-%1$s > .quform-child-elements {', $this->getIdentifier());
97:
98: if ($this->config('borderColor')) {
99: $css .= 'border-color: ' . esc_attr($this->config('borderColor')) . '!important;';
100: }
101: if ($this->config('backgroundColor')) {
102: $css .= 'background-color: ' . esc_attr($this->config('backgroundColor')) . '!important;';
103: }
104:
105: $css .= '}';
106: }
107:
108: $css .= parent::renderCss($context);
109:
110: return $css;
111: }
112:
113: 114: 115: 116: 117:
118: protected function getCssSelectors()
119: {
120: return array(
121: 'group' => '%s .quform-element-%s',
122: 'groupSpacer' => '%s .quform-element-%s > .quform-spacer',
123: 'groupTitle' => '%s .quform-element-%s > .quform-spacer > .quform-group-title-description .quform-group-title',
124: 'groupDescription' => '%s .quform-element-%s > .quform-spacer > .quform-group-title-description p.quform-group-description',
125: 'groupElements' => '%s .quform-element-%s > .quform-spacer > .quform-child-elements'
126: );
127: }
128:
129: 130: 131: 132: 133: 134:
135: public static function getDefaultConfig($key = null)
136: {
137: $config = apply_filters('quform_default_config_group', array(
138:
139: 'label' => __('Untitled group', 'quform'),
140: 'title' => '',
141: 'titleTag' => 'h4',
142: 'description' => '',
143:
144:
145: 'fieldSize' => 'inherit',
146: 'fieldWidth' => 'inherit',
147: 'fieldWidthCustom' => '',
148: 'groupStyle' => 'plain',
149: 'borderColor' => '',
150: 'backgroundColor' => '',
151: 'customElementClass' => '',
152: 'styles' => array(),
153:
154:
155: 'tooltipType' => 'inherit',
156: 'tooltipEvent' => 'inherit',
157: 'labelPosition' => 'inherit',
158: 'labelWidth' => '',
159: 'showLabelInEmail' => false,
160: 'showLabelInEntry' => false,
161:
162:
163: 'logicEnabled' => false,
164: 'logicAction' => true,
165: 'logicMatch' => 'all',
166: 'logicRules' => array(),
167:
168:
169: 'visibility' => '',
170:
171:
172: 'elements' => array()
173: ));
174:
175: $config['type'] = 'group';
176:
177: if (Quform::isNonEmptyString($key)) {
178: return Quform::get($config, $key);
179: }
180:
181: return $config;
182: }
183: }
184: