field-advanced-link.php
3 months ago
field-button-group.php
1 week ago
field-button.php
7 months ago
field-checkbox.php
3 months ago
field-clone.php
2 years ago
field-code-editor.php
3 months ago
field-column.php
3 years ago
field-dynamic-render.php
3 years ago
field-file.php
3 months ago
field-flexible-content-actions-title.php
3 months ago
field-flexible-content-actions-toggle.php
3 months ago
field-flexible-content-actions.php
3 months ago
field-flexible-content-async.php
4 months ago
field-flexible-content-compatibility.php
3 months ago
field-flexible-content-controls.php
9 months ago
field-flexible-content-hide.php
3 months ago
field-flexible-content-hooks.php
9 months ago
field-flexible-content-modal-edit.php
9 months ago
field-flexible-content-modal-select.php
3 months ago
field-flexible-content-modal-settings.php
3 months ago
field-flexible-content-popup.php
3 months ago
field-flexible-content-preview.php
3 months ago
field-flexible-content-state.php
9 months ago
field-flexible-content-thumbnail.php
9 months ago
field-flexible-content-wysiwyg.php
9 months ago
field-flexible-content.php
3 months ago
field-forms.php
3 months ago
field-gallery.php
3 months ago
field-google-map.php
3 months ago
field-group.php
3 months ago
field-hidden.php
3 years ago
field-image.php
3 months ago
field-post-object.php
3 months ago
field-post-statuses.php
3 months ago
field-post-types.php
3 months ago
field-radio.php
3 months ago
field-recaptcha.php
3 months ago
field-relationship.php
3 months ago
field-repeater.php
3 months ago
field-select.php
3 months ago
field-slug.php
1 year ago
field-taxonomies.php
3 months ago
field-taxonomy-terms.php
3 months ago
field-taxonomy.php
3 months ago
field-textarea.php
3 months ago
field-user-roles.php
3 months ago
field-user.php
3 months ago
field-wysiwyg.php
3 months ago
field-group.php
237 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_group_field')): |
| 8 | |
| 9 | class acfe_field_group_field extends acfe_field_extend{ |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | */ |
| 14 | function initialize(){ |
| 15 | |
| 16 | $this->name = 'group'; |
| 17 | $this->defaults = array( |
| 18 | 'acfe_seamless_style' => 0, |
| 19 | 'acfe_group_modal' => 0, |
| 20 | 'acfe_group_modal_close' => 0, |
| 21 | 'acfe_group_modal_button' => '', |
| 22 | 'acfe_group_modal_size' => 'large', |
| 23 | ); |
| 24 | |
| 25 | } |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * render_field_settings |
| 30 | * |
| 31 | * @param $field |
| 32 | */ |
| 33 | function render_field_settings($field){ |
| 34 | |
| 35 | acf_render_field_setting($field, array( |
| 36 | 'label' => __('Seamless Style', 'acfe'), |
| 37 | 'name' => 'acfe_seamless_style', |
| 38 | 'instructions' => __('Enable better CSS integration: remove borders and padding'), |
| 39 | 'type' => 'true_false', |
| 40 | 'message' => '', |
| 41 | 'default_value' => false, |
| 42 | 'ui' => true, |
| 43 | 'conditional_logic' => array( |
| 44 | array( |
| 45 | array( |
| 46 | 'field' => 'acfe_group_modal', |
| 47 | 'operator' => '!=', |
| 48 | 'value' => '1', |
| 49 | ) |
| 50 | ) |
| 51 | ) |
| 52 | )); |
| 53 | |
| 54 | acf_render_field_setting($field, array( |
| 55 | 'label' => __('Edition modal'), |
| 56 | 'name' => 'acfe_group_modal', |
| 57 | 'instructions' => __('Edit fields in a modal'), |
| 58 | 'type' => 'true_false', |
| 59 | 'message' => '', |
| 60 | 'default_value' => false, |
| 61 | 'ui' => true, |
| 62 | 'conditional_logic' => array( |
| 63 | array( |
| 64 | array( |
| 65 | 'field' => 'acfe_seamless_style', |
| 66 | 'operator' => '!=', |
| 67 | 'value' => '1', |
| 68 | ) |
| 69 | ) |
| 70 | ) |
| 71 | )); |
| 72 | |
| 73 | acf_render_field_setting($field, array( |
| 74 | 'label' => __('Edition modal: Close button'), |
| 75 | 'name' => 'acfe_group_modal_close', |
| 76 | 'instructions' => __('Display close button'), |
| 77 | 'type' => 'true_false', |
| 78 | 'message' => '', |
| 79 | 'default_value' => false, |
| 80 | 'ui' => true, |
| 81 | 'conditional_logic' => array( |
| 82 | array( |
| 83 | array( |
| 84 | 'field' => 'acfe_group_modal', |
| 85 | 'operator' => '==', |
| 86 | 'value' => '1', |
| 87 | ), |
| 88 | ) |
| 89 | ) |
| 90 | )); |
| 91 | |
| 92 | acf_render_field_setting($field, array( |
| 93 | 'label' => __('Edition modal: Text button'), |
| 94 | 'name' => 'acfe_group_modal_button', |
| 95 | 'instructions' => __('Text displayed in the edition modal button'), |
| 96 | 'type' => 'text', |
| 97 | 'placeholder' => __('Edit', 'acf'), |
| 98 | 'conditional_logic' => array( |
| 99 | array( |
| 100 | array( |
| 101 | 'field' => 'acfe_group_modal', |
| 102 | 'operator' => '==', |
| 103 | 'value' => '1', |
| 104 | ), |
| 105 | ) |
| 106 | ) |
| 107 | )); |
| 108 | |
| 109 | acf_render_field_setting($field, array( |
| 110 | 'label' => __('Edition modal: Size'), |
| 111 | 'name' => 'acfe_group_modal_size', |
| 112 | 'instructions' => __('Choose the modal size'), |
| 113 | 'type' => 'select', |
| 114 | 'choices' => array( |
| 115 | 'small' => 'Small', |
| 116 | 'medium' => 'Medium', |
| 117 | 'large' => 'Large', |
| 118 | 'full' => 'Full', |
| 119 | ), |
| 120 | 'default_value' => 'large', |
| 121 | 'conditional_logic' => array( |
| 122 | array( |
| 123 | array( |
| 124 | 'field' => 'acfe_group_modal', |
| 125 | 'operator' => '==', |
| 126 | 'value' => '1', |
| 127 | ), |
| 128 | ) |
| 129 | ) |
| 130 | )); |
| 131 | |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /** |
| 136 | * prepare_field |
| 137 | * |
| 138 | * @param $field |
| 139 | * |
| 140 | * @return array |
| 141 | */ |
| 142 | function prepare_field($field){ |
| 143 | |
| 144 | // seamless style |
| 145 | if($field['acfe_seamless_style']){ |
| 146 | $field['wrapper']['class'] .= ' acfe-seamless-style'; |
| 147 | } |
| 148 | |
| 149 | // class |
| 150 | $field['wrapper']['class'] .= ' acfe-field-group-layout-' . $field['layout']; |
| 151 | |
| 152 | // modal edit |
| 153 | if($field['acfe_group_modal']){ |
| 154 | |
| 155 | $field['wrapper']['data-acfe-group-modal'] = $field['acfe_group_modal']; |
| 156 | $field['wrapper']['data-acfe-group-modal-button'] = $field['acfe_group_modal_button'] ? $field['acfe_group_modal_button'] : __('Edit', 'acf'); |
| 157 | $field['wrapper']['data-acfe-group-modal-close'] = $field['acfe_group_modal_close']; |
| 158 | $field['wrapper']['data-acfe-group-modal-size'] = $field['acfe_group_modal_size']; |
| 159 | |
| 160 | } |
| 161 | |
| 162 | // return |
| 163 | return $field; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | |
| 168 | /** |
| 169 | * format_front_value |
| 170 | * |
| 171 | * @param $formatted |
| 172 | * @param $unformatted |
| 173 | * @param $post_id |
| 174 | * @param $field |
| 175 | * @param $form |
| 176 | * |
| 177 | * @return string |
| 178 | */ |
| 179 | function format_front_value($formatted, $unformatted, $post_id, $field, $form){ |
| 180 | |
| 181 | // vars |
| 182 | $value = acfe_as_array($unformatted); |
| 183 | $array = array(); |
| 184 | $return = ''; |
| 185 | |
| 186 | // loop subfields keys |
| 187 | foreach($value as $key => $val){ |
| 188 | |
| 189 | // get sub field |
| 190 | $sub_field = acf_get_field($key); |
| 191 | |
| 192 | // validate |
| 193 | if($sub_field){ |
| 194 | |
| 195 | // label |
| 196 | $label = !empty($sub_field['label']) ? $sub_field['label'] : $sub_field['name']; |
| 197 | |
| 198 | // format value |
| 199 | $sub_field['name'] = $field['name'] . '_' . $sub_field['name']; |
| 200 | $val = acfe_form_format_value($val, $sub_field); |
| 201 | |
| 202 | // append |
| 203 | $array[] = "{$label}: {$val}"; |
| 204 | |
| 205 | } |
| 206 | |
| 207 | } |
| 208 | |
| 209 | // merge |
| 210 | $return .= implode(', ', $array); |
| 211 | |
| 212 | // return |
| 213 | return $return; |
| 214 | |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /** |
| 219 | * translate_field |
| 220 | * |
| 221 | * @param $field |
| 222 | * |
| 223 | * @return mixed |
| 224 | */ |
| 225 | function translate_field($field){ |
| 226 | |
| 227 | $field['acfe_group_modal_button'] = acf_translate($field['acfe_group_modal_button']); |
| 228 | |
| 229 | return $field; |
| 230 | |
| 231 | } |
| 232 | |
| 233 | } |
| 234 | |
| 235 | acf_new_instance('acfe_field_group_field'); |
| 236 | |
| 237 | endif; |