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-flexible-content-modal-settings.php
458 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_flexible_content_settings')): |
| 8 | |
| 9 | class acfe_field_flexible_content_settings{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | // Hooks |
| 17 | add_filter('acfe/flexible/defaults_field', array($this, 'defaults_field'), 4); |
| 18 | add_filter('acfe/flexible/defaults_layout', array($this, 'defaults_layout'), 4); |
| 19 | |
| 20 | add_action('acfe/flexible/render_field_settings', array($this, 'render_field_settings'), 11); |
| 21 | add_action('acfe/flexible/render_layout_settings', array($this, 'render_layout_settings'), 20, 3); |
| 22 | |
| 23 | add_filter('acfe/flexible/load_fields', array($this, 'load_fields'), 10, 2); |
| 24 | add_filter('acfe/flexible/prepare_layout', array($this, 'prepare_layout'), 30, 5); |
| 25 | add_filter('acfe/flexible/layouts/icons', array($this, 'layout_icons'), 30, 3); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * defaults_field |
| 32 | * |
| 33 | * @param $field |
| 34 | * |
| 35 | * @return mixed |
| 36 | */ |
| 37 | function defaults_field($field){ |
| 38 | |
| 39 | $field['acfe_flexible_modal_settings'] = array( |
| 40 | 'acfe_flexible_modal_settings_enabled' => false, |
| 41 | 'acfe_flexible_modal_settings_size' => 'large', |
| 42 | 'acfe_flexible_modal_settings_close' => true, |
| 43 | 'acfe_flexible_modal_settings_close_label' => '', |
| 44 | ); |
| 45 | |
| 46 | return $field; |
| 47 | |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * defaults_layout |
| 53 | * |
| 54 | * @param $layout |
| 55 | * |
| 56 | * @return mixed |
| 57 | */ |
| 58 | function defaults_layout($layout){ |
| 59 | |
| 60 | $layout['acfe_flexible_settings'] = false; |
| 61 | $layout['acfe_flexible_settings_size'] = false; |
| 62 | |
| 63 | return $layout; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * render_field_settings |
| 70 | * |
| 71 | * @param $field |
| 72 | */ |
| 73 | function render_field_settings($field){ |
| 74 | |
| 75 | acf_render_field_setting($field, array( |
| 76 | 'label' => __('Settings Modal', 'acfe'), |
| 77 | 'name' => 'acfe_flexible_modal_settings', |
| 78 | 'key' => 'acfe_flexible_modal_settings', |
| 79 | 'instructions' => __('Display a settings modal for each layouts', 'acfe') . '. ' . '<a href="https://www.acf-extended.com/features/fields/flexible-content/modal-settings#settings-modal" target="_blank">' . __('See documentation', 'acfe') . '</a>', |
| 80 | 'type' => 'group', |
| 81 | 'layout' => 'block', |
| 82 | 'sub_fields' => array( |
| 83 | array( |
| 84 | 'label' => '', |
| 85 | 'name' => 'acfe_flexible_modal_settings_enabled', |
| 86 | 'key' => 'acfe_flexible_modal_settings_enabled', |
| 87 | 'type' => 'true_false', |
| 88 | 'instructions' => '', |
| 89 | 'required' => false, |
| 90 | 'wrapper' => array( |
| 91 | 'class' => 'acfe_width_auto', |
| 92 | 'id' => '', |
| 93 | ), |
| 94 | 'message' => '', |
| 95 | 'default_value' => false, |
| 96 | 'ui' => true, |
| 97 | 'ui_on_text' => '', |
| 98 | 'ui_off_text' => '', |
| 99 | 'conditional_logic' => false, |
| 100 | ), |
| 101 | array( |
| 102 | 'label' => '', |
| 103 | 'name' => 'acfe_flexible_modal_settings_size', |
| 104 | 'key' => 'acfe_flexible_modal_settings_size', |
| 105 | 'type' => 'select', |
| 106 | 'prepend' => '', |
| 107 | 'instructions' => false, |
| 108 | 'required' => false, |
| 109 | 'choices' => array( |
| 110 | 'small' => __('Small', 'acfe'), |
| 111 | 'medium' => __('Medium', 'acfe'), |
| 112 | 'large' => __('Large', 'acfe'), |
| 113 | 'xlarge' => __('Extra Large', 'acfe'), |
| 114 | 'full' => __('Full', 'acfe'), |
| 115 | ), |
| 116 | 'default_value' => 'large', |
| 117 | 'wrapper' => array( |
| 118 | 'width' => '25', |
| 119 | 'class' => '', |
| 120 | 'id' => '', |
| 121 | 'data-acfe-prepend' => __('Default Size', 'acfe'), |
| 122 | ), |
| 123 | 'conditional_logic' => array( |
| 124 | array( |
| 125 | array( |
| 126 | 'field' => 'acfe_flexible_modal_settings_enabled', |
| 127 | 'operator' => '==', |
| 128 | 'value' => '1', |
| 129 | ) |
| 130 | ) |
| 131 | ) |
| 132 | ), |
| 133 | array( |
| 134 | 'label' => '', |
| 135 | 'name' => 'acfe_flexible_modal_settings_close', |
| 136 | 'key' => 'acfe_flexible_modal_settings_close', |
| 137 | 'type' => 'select', |
| 138 | 'prepend' => '', |
| 139 | 'instructions' => false, |
| 140 | 'required' => false, |
| 141 | 'choices' => array( |
| 142 | '1' => __('Enabled', 'acfe'), |
| 143 | ), |
| 144 | 'allow_null' => true, |
| 145 | 'placeholder' => __('Disabled', 'acfe'), |
| 146 | 'wrapper' => array( |
| 147 | 'width' => '25', |
| 148 | 'class' => 'acfe_width_auto', |
| 149 | 'id' => '', |
| 150 | 'data-acfe-prepend' => __('Close Button', 'acfe'), |
| 151 | ), |
| 152 | 'conditional_logic' => array( |
| 153 | array( |
| 154 | array( |
| 155 | 'field' => 'acfe_flexible_modal_settings_enabled', |
| 156 | 'operator' => '==', |
| 157 | 'value' => '1', |
| 158 | ) |
| 159 | ) |
| 160 | ) |
| 161 | ), |
| 162 | array( |
| 163 | 'label' => '', |
| 164 | 'name' => 'acfe_flexible_modal_settings_close_label', |
| 165 | 'key' => 'acfe_flexible_modal_settings_close_label', |
| 166 | 'type' => 'text', |
| 167 | 'prepend' => __('Close Label', 'acfe'), |
| 168 | 'instructions' => false, |
| 169 | 'required' => false, |
| 170 | 'default_value' => '', |
| 171 | 'placeholder' => __('Close', 'acfe'), |
| 172 | 'wrapper' => array( |
| 173 | 'width' => '25', |
| 174 | 'class' => 'acfe_width_auto', |
| 175 | 'id' => '', |
| 176 | ), |
| 177 | 'conditional_logic' => array( |
| 178 | array( |
| 179 | array( |
| 180 | 'field' => 'acfe_flexible_modal_settings_enabled', |
| 181 | 'operator' => '==', |
| 182 | 'value' => '1', |
| 183 | ), |
| 184 | array( |
| 185 | 'field' => 'acfe_flexible_modal_settings_close', |
| 186 | 'operator' => '==', |
| 187 | 'value' => '1', |
| 188 | ) |
| 189 | ) |
| 190 | ) |
| 191 | ), |
| 192 | ), |
| 193 | 'conditional_logic' => array( |
| 194 | array( |
| 195 | array( |
| 196 | 'field' => 'acfe_flexible_advanced', |
| 197 | 'operator' => '==', |
| 198 | 'value' => '1', |
| 199 | ), |
| 200 | ) |
| 201 | ), |
| 202 | 'wrapper' => array( |
| 203 | 'class' => 'acfe-field-setting-flex' |
| 204 | ) |
| 205 | )); |
| 206 | |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /** |
| 211 | * render_layout_settings |
| 212 | * |
| 213 | * @param $field |
| 214 | * @param $layout |
| 215 | * @param $prefix |
| 216 | */ |
| 217 | function render_layout_settings($field, $layout, $prefix){ |
| 218 | |
| 219 | if(!$field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_enabled']){ |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | acf_disable_filters(); |
| 224 | |
| 225 | $choices = array(); |
| 226 | |
| 227 | $field_groups = acf_get_field_groups(); |
| 228 | if(!empty($field_groups)){ |
| 229 | |
| 230 | foreach($field_groups as $field_group){ |
| 231 | $choices[$field_group['key']] = $field_group['title']; |
| 232 | } |
| 233 | |
| 234 | } |
| 235 | |
| 236 | acf_enable_filters(); |
| 237 | |
| 238 | // Title |
| 239 | echo '</li>'; |
| 240 | acf_render_field_wrap(array( |
| 241 | 'label' => __('Settings Modal', 'acfe'), |
| 242 | 'type' => 'hidden', |
| 243 | 'name' => 'acfe_flexible_settings_label', |
| 244 | 'wrapper' => array( |
| 245 | 'class' => 'acfe-flexible-field-setting', |
| 246 | ) |
| 247 | ), 'ul'); |
| 248 | echo '<li>'; |
| 249 | |
| 250 | // Fields |
| 251 | acf_render_field_wrap(array( |
| 252 | 'label' => '', |
| 253 | 'name' => 'acfe_flexible_settings', |
| 254 | 'type' => 'select', |
| 255 | 'class' => '', |
| 256 | 'prefix' => $prefix, |
| 257 | 'value' => $layout['acfe_flexible_settings'], |
| 258 | 'choices' => $choices, |
| 259 | 'wrapper' => array( |
| 260 | 'data-acfe-prepend' => __('Clone fields', 'acfe'), |
| 261 | ), |
| 262 | 'allow_null' => 1, |
| 263 | 'multiple' => 1, |
| 264 | 'ui' => 1, |
| 265 | 'ajax' => 0, |
| 266 | 'return_format' => 0, |
| 267 | ), 'ul'); |
| 268 | |
| 269 | acf_render_field_wrap(array( |
| 270 | 'label' => '', |
| 271 | 'name' => 'acfe_flexible_settings_size', |
| 272 | 'type' => 'select', |
| 273 | 'class' => '', |
| 274 | 'prefix' => $prefix, |
| 275 | 'value' => $layout['acfe_flexible_settings_size'], |
| 276 | 'choices' => array( |
| 277 | 'small' => __('Small', 'acfe'), |
| 278 | 'medium' => __('Medium', 'acfe'), |
| 279 | 'large' => __('Large', 'acfe'), |
| 280 | 'xlarge' => __('Extra Large', 'acfe'), |
| 281 | 'full' => __('Full', 'acfe'), |
| 282 | ), |
| 283 | 'wrapper' => array( |
| 284 | 'data-acfe-prepend' => __('Modal size', 'acfe'), |
| 285 | ), |
| 286 | 'allow_null' => true, |
| 287 | 'placeholder' => __('Default', 'acfe'), |
| 288 | 'multiple' => 0, |
| 289 | 'ui' => 0, |
| 290 | 'ajax' => 0, |
| 291 | 'return_format' => 0, |
| 292 | ), 'ul'); |
| 293 | |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /** |
| 298 | * load_fields |
| 299 | * |
| 300 | * @param $fields |
| 301 | * @param $field |
| 302 | * |
| 303 | * @return mixed |
| 304 | */ |
| 305 | function load_fields($fields, $field){ |
| 306 | |
| 307 | // check setting |
| 308 | if(!$field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_enabled']){ |
| 309 | return $fields; |
| 310 | } |
| 311 | |
| 312 | // Loop |
| 313 | foreach($field['layouts'] as $i => $layout){ |
| 314 | |
| 315 | $field_groups = acfe_get($layout, 'acfe_flexible_settings', array()); |
| 316 | $field_groups = acfe_as_array($field_groups); |
| 317 | |
| 318 | // Check |
| 319 | if(empty($field_groups)){ |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | // Vars |
| 324 | $key = "field_{$layout['key']}_settings"; |
| 325 | $name = 'layout_settings'; |
| 326 | $style = 'row'; |
| 327 | $field_group = acf_get_field_group($field_groups[0]); |
| 328 | |
| 329 | if($field_group){ |
| 330 | $style = $field_group['label_placement'] === 'left' ? 'row' : 'block'; |
| 331 | } |
| 332 | |
| 333 | // Add local |
| 334 | acf_add_local_field(array( |
| 335 | 'label' => false, |
| 336 | 'key' => $key, |
| 337 | 'name' => $name, |
| 338 | 'type' => 'clone', |
| 339 | 'clone' => $field_groups, |
| 340 | 'display' => 'group', |
| 341 | 'acfe_seamless_style' => true, |
| 342 | 'layout' => $style, |
| 343 | 'prefix_label' => 0, |
| 344 | 'prefix_name' => 1, |
| 345 | 'parent_layout' => $layout['key'], |
| 346 | 'parent' => $field['key'] |
| 347 | )); |
| 348 | |
| 349 | // Add sub field |
| 350 | array_unshift($fields, acf_get_field($key)); |
| 351 | |
| 352 | } |
| 353 | |
| 354 | return $fields; |
| 355 | |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /** |
| 360 | * prepare_layout |
| 361 | * |
| 362 | * @param $layout |
| 363 | * @param $field |
| 364 | * @param $i |
| 365 | * @param $value |
| 366 | * @param $prefix |
| 367 | * |
| 368 | * @return mixed |
| 369 | */ |
| 370 | function prepare_layout($layout, $field, $i, $value, $prefix){ |
| 371 | |
| 372 | if(empty($layout['sub_fields']) || !$field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_enabled']){ |
| 373 | return $layout; |
| 374 | } |
| 375 | |
| 376 | // subfield |
| 377 | $sub_field = acfe_extract_sub_field($layout, 'layout_settings', $value); |
| 378 | |
| 379 | if(!$sub_field){ |
| 380 | return $layout; |
| 381 | } |
| 382 | |
| 383 | // update prefix to allow for nested values |
| 384 | $sub_field['prefix'] = $prefix; |
| 385 | |
| 386 | // modal |
| 387 | $modal = array( |
| 388 | 'class' => "acfe-modal -settings acfe-modal-settings-{$field['_name']} acfe-modal-settings-{$field['key']} acfe-modal-settings-{$layout['name']}", |
| 389 | ); |
| 390 | |
| 391 | // modal size |
| 392 | $modal['data-size'] = $field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_size']; |
| 393 | |
| 394 | if(!empty($layout['acfe_flexible_settings_size'])){ |
| 395 | $modal['data-size'] = $layout['acfe_flexible_settings_size']; |
| 396 | } |
| 397 | |
| 398 | // modal close button |
| 399 | if($field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_close']){ |
| 400 | $modal['data-footer'] = __('Close', 'acfe'); |
| 401 | |
| 402 | if(!empty($field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_close_label'])){ |
| 403 | $modal['data-footer'] = $field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_close_label']; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | ?> |
| 408 | <div <?php echo acf_esc_atts($modal); ?>> |
| 409 | <div class="acfe-modal-wrapper"> |
| 410 | <div class="acfe-modal-content"> |
| 411 | <div class="acf-fields -top"> |
| 412 | <?php acf_render_field_wrap($sub_field); ?> |
| 413 | </div> |
| 414 | </div> |
| 415 | </div> |
| 416 | </div> |
| 417 | <?php |
| 418 | |
| 419 | return $layout; |
| 420 | |
| 421 | } |
| 422 | |
| 423 | |
| 424 | /** |
| 425 | * layout_icons |
| 426 | * |
| 427 | * @param $icons |
| 428 | * @param $layout |
| 429 | * @param $field |
| 430 | * |
| 431 | * @return mixed |
| 432 | */ |
| 433 | function layout_icons($icons, $layout, $field){ |
| 434 | |
| 435 | if(!$field['acfe_flexible_modal_settings']['acfe_flexible_modal_settings_enabled'] || !$layout['acfe_flexible_settings']){ |
| 436 | return $icons; |
| 437 | } |
| 438 | |
| 439 | // try to before after 'collapse' icon |
| 440 | if(isset($icons['collapse'])){ |
| 441 | $icons = acfe_before($icons, 'collapse', array( |
| 442 | 'settings' => '<a class="acf-js-tooltip" href="#" data-name="acfe-settings" title="' . esc_attr__('Settings', 'acfe') . '"><span class="acf-icon -settings"></span></a>' |
| 443 | )); |
| 444 | |
| 445 | // otherwise, append at the end |
| 446 | }else{ |
| 447 | $icons['settings'] = '<a class="acf-js-tooltip" href="#" data-name="acfe-settings" title="' . esc_attr__('Settings', 'acfe') . '"><span class="acf-icon -settings"></span></a>'; |
| 448 | } |
| 449 | |
| 450 | return $icons; |
| 451 | |
| 452 | } |
| 453 | |
| 454 | } |
| 455 | |
| 456 | acf_new_instance('acfe_field_flexible_content_settings'); |
| 457 | |
| 458 | endif; |