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-edit.php
406 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_flexible_content_edit')): |
| 8 | |
| 9 | class acfe_field_flexible_content_edit{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | // Hooks |
| 17 | add_filter('acfe/flexible/defaults_field', array($this, 'defaults_field'), 9); |
| 18 | add_filter('acfe/flexible/defaults_layout', array($this, 'defaults_layout'), 9); |
| 19 | |
| 20 | add_action('acfe/flexible/render_field_settings', array($this, 'render_field_settings'), 9); |
| 21 | add_action('acfe/flexible/render_layout_settings', array($this, 'render_layout_settings'), 19, 3); |
| 22 | add_filter('acfe/flexible/wrapper_attributes', array($this, 'wrapper_attributes'), 10, 2); |
| 23 | add_action('acfe/flexible/pre_render_layout', array($this, 'pre_render_layout'), 5, 5); |
| 24 | add_action('acfe/flexible/render_layout', array($this, 'render_layout'), 20, 5); |
| 25 | add_filter('acfe/flexible/layouts/div', array($this, 'layout_div'), 10, 3); |
| 26 | add_filter('acfe/flexible/layouts/icons', array($this, 'layout_icons'), 50, 3); |
| 27 | add_filter('acfe/flexible/layouts/handle', array($this, 'layout_handle'), 10, 3); |
| 28 | add_filter('acfe/flexible/layouts/placeholder', array($this, 'layout_handle'), 10, 3); |
| 29 | add_filter('acfe/flexible/action_buttons', array($this, 'action_buttons'), 10, 3); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * defaults_field |
| 36 | * |
| 37 | * @param $field |
| 38 | * |
| 39 | * @return mixed |
| 40 | */ |
| 41 | function defaults_field($field){ |
| 42 | |
| 43 | $field['acfe_flexible_modal_edit'] = array( |
| 44 | 'acfe_flexible_modal_edit_enabled' => false, |
| 45 | 'acfe_flexible_modal_edit_size' => 'large', |
| 46 | ); |
| 47 | |
| 48 | return $field; |
| 49 | |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * defaults_layout |
| 55 | * |
| 56 | * @param $layout |
| 57 | * |
| 58 | * @return mixed |
| 59 | */ |
| 60 | function defaults_layout($layout){ |
| 61 | |
| 62 | $layout['acfe_flexible_modal_edit_size'] = false; |
| 63 | |
| 64 | return $layout; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | |
| 69 | /** |
| 70 | * render_field_settings |
| 71 | * |
| 72 | * @param $field |
| 73 | */ |
| 74 | function render_field_settings($field){ |
| 75 | |
| 76 | acf_render_field_setting($field, array( |
| 77 | 'label' => __('Edit Modal', 'acfe'), |
| 78 | 'name' => 'acfe_flexible_modal_edit', |
| 79 | 'key' => 'acfe_flexible_modal_edit', |
| 80 | 'instructions' => __('Edit layout content in a modal', 'acfe') . '. ' . '<a href="https://www.acf-extended.com/features/fields/flexible-content/modal-settings#edit-modal" target="_blank">' . __('See documentation', 'acfe') . '</a>', |
| 81 | 'type' => 'group', |
| 82 | 'layout' => 'block', |
| 83 | 'sub_fields' => array( |
| 84 | array( |
| 85 | 'label' => '', |
| 86 | 'name' => 'acfe_flexible_modal_edit_enabled', |
| 87 | 'key' => 'acfe_flexible_modal_edit_enabled', |
| 88 | 'type' => 'true_false', |
| 89 | 'instructions' => '', |
| 90 | 'required' => false, |
| 91 | 'wrapper' => array( |
| 92 | 'class' => 'acfe_width_auto', |
| 93 | 'id' => '', |
| 94 | ), |
| 95 | 'message' => '', |
| 96 | 'default_value' => false, |
| 97 | 'ui' => true, |
| 98 | 'ui_on_text' => '', |
| 99 | 'ui_off_text' => '', |
| 100 | 'conditional_logic' => false, |
| 101 | ), |
| 102 | array( |
| 103 | 'label' => '', |
| 104 | 'name' => 'acfe_flexible_modal_edit_size', |
| 105 | 'key' => 'acfe_flexible_modal_edit_size', |
| 106 | 'type' => 'select', |
| 107 | 'prepend' => '', |
| 108 | 'instructions' => false, |
| 109 | 'required' => false, |
| 110 | 'choices' => array( |
| 111 | 'small' => __('Small', 'acfe'), |
| 112 | 'medium' => __('Medium', 'acfe'), |
| 113 | 'large' => __('Large', 'acfe'), |
| 114 | 'xlarge' => __('Extra Large', 'acfe'), |
| 115 | 'full' => __('Full', 'acfe'), |
| 116 | ), |
| 117 | 'default_value' => 'large', |
| 118 | 'wrapper' => array( |
| 119 | 'width' => '25', |
| 120 | 'class' => '', |
| 121 | 'id' => '', |
| 122 | 'data-acfe-prepend' => __('Default Size', 'acfe'), |
| 123 | ), |
| 124 | 'conditional_logic' => array( |
| 125 | array( |
| 126 | array( |
| 127 | 'field' => 'acfe_flexible_modal_edit_enabled', |
| 128 | 'operator' => '==', |
| 129 | 'value' => '1', |
| 130 | ) |
| 131 | ) |
| 132 | ) |
| 133 | ), |
| 134 | ), |
| 135 | 'conditional_logic' => array( |
| 136 | array( |
| 137 | array( |
| 138 | 'field' => 'acfe_flexible_advanced', |
| 139 | 'operator' => '==', |
| 140 | 'value' => '1', |
| 141 | ), |
| 142 | array( |
| 143 | 'field' => 'acfe_flexible_layouts_state', |
| 144 | 'operator' => '!=', |
| 145 | 'value' => 'force_open', |
| 146 | ), |
| 147 | array( |
| 148 | 'field' => 'acfe_flexible_layouts_state', |
| 149 | 'operator' => '!=', |
| 150 | 'value' => 'open', |
| 151 | ), |
| 152 | ) |
| 153 | ), |
| 154 | 'wrapper' => array( |
| 155 | 'class' => 'acfe-field-setting-flex' |
| 156 | ) |
| 157 | )); |
| 158 | |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * render_layout_settings |
| 164 | * |
| 165 | * @param $field |
| 166 | * @param $layout |
| 167 | * @param $prefix |
| 168 | */ |
| 169 | function render_layout_settings($field, $layout, $prefix){ |
| 170 | |
| 171 | if(!$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | // Title |
| 176 | echo '</li>'; |
| 177 | acf_render_field_wrap(array( |
| 178 | 'label' => __('Edit Modal', 'acfe'), |
| 179 | 'type' => 'hidden', |
| 180 | 'name' => 'acfe_flexible_modal_edit_label', |
| 181 | 'wrapper' => array( |
| 182 | 'class' => 'acfe-flexible-field-setting', |
| 183 | ) |
| 184 | ), 'ul'); |
| 185 | echo '<li>'; |
| 186 | |
| 187 | acf_render_field_wrap(array( |
| 188 | 'label' => '', |
| 189 | 'name' => 'acfe_flexible_modal_edit_size', |
| 190 | 'type' => 'select', |
| 191 | 'class' => '', |
| 192 | 'prefix' => $prefix, |
| 193 | 'value' => $layout['acfe_flexible_modal_edit_size'], |
| 194 | 'placeholder' => 'Default', |
| 195 | 'choices' => array( |
| 196 | 'small' => __('Small', 'acfe'), |
| 197 | 'medium' => __('Medium', 'acfe'), |
| 198 | 'large' => __('Large', 'acfe'), |
| 199 | 'xlarge' => __('Extra Large', 'acfe'), |
| 200 | 'full' => __('Full', 'acfe'), |
| 201 | ), |
| 202 | 'wrapper' => array( |
| 203 | 'width' => '100', |
| 204 | 'data-acfe-prepend' => 'Modal size', |
| 205 | ), |
| 206 | 'default_value' => '', |
| 207 | 'allow_null' => 1, |
| 208 | 'multiple' => 0, |
| 209 | 'ui' => 0, |
| 210 | 'ajax' => 0, |
| 211 | 'return_format' => 0, |
| 212 | ), 'ul'); |
| 213 | |
| 214 | } |
| 215 | |
| 216 | |
| 217 | /** |
| 218 | * wrapper_attributes |
| 219 | * |
| 220 | * @param $wrapper |
| 221 | * @param $field |
| 222 | * |
| 223 | * @return mixed |
| 224 | */ |
| 225 | function wrapper_attributes($wrapper, $field){ |
| 226 | |
| 227 | // check setting |
| 228 | if(!$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 229 | return $wrapper; |
| 230 | } |
| 231 | |
| 232 | $wrapper['data-acfe-flexible-modal-edition'] = 1; |
| 233 | |
| 234 | return $wrapper; |
| 235 | |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /** |
| 240 | * pre_render_layout |
| 241 | * |
| 242 | * @param $layout |
| 243 | * @param $field |
| 244 | * @param $i |
| 245 | * @param $value |
| 246 | * @param $prefix |
| 247 | */ |
| 248 | function pre_render_layout($layout, $field, $i, $value, $prefix){ |
| 249 | |
| 250 | if(empty($layout['sub_fields']) || !$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 251 | return; |
| 252 | } |
| 253 | |
| 254 | // modal |
| 255 | $modal = array( |
| 256 | 'class' => "acfe-modal -edit acfe-modal-edit-{$field['_name']} acfe-modal-edit-{$field['key']} acfe-modal-edit-{$layout['name']} -fields", |
| 257 | 'data-size' => $field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_size'], |
| 258 | ); |
| 259 | |
| 260 | if(!empty($layout['acfe_flexible_modal_edit_size'])){ |
| 261 | $modal['data-size'] = $layout['acfe_flexible_modal_edit_size']; |
| 262 | } |
| 263 | |
| 264 | if(in_array('close', $field['acfe_flexible_add_actions'])){ |
| 265 | |
| 266 | $modal['data-footer'] = __('Close', 'acfe'); |
| 267 | |
| 268 | if(!empty($field['acfe_flexible_close_button_label'])){ |
| 269 | $modal['data-footer'] = $field['acfe_flexible_close_button_label']; |
| 270 | } |
| 271 | |
| 272 | } |
| 273 | |
| 274 | ?> |
| 275 | <div <?php echo acf_esc_atts($modal); ?>> |
| 276 | <div class="acfe-modal-wrapper"> |
| 277 | <div class="acfe-modal-content"> |
| 278 | <?php |
| 279 | |
| 280 | } |
| 281 | |
| 282 | |
| 283 | /** |
| 284 | * render_layout |
| 285 | * |
| 286 | * @param $layout |
| 287 | * @param $field |
| 288 | * @param $i |
| 289 | * @param $value |
| 290 | * @param $prefix |
| 291 | */ |
| 292 | function render_layout($layout, $field, $i, $value, $prefix){ |
| 293 | |
| 294 | if(empty($layout['sub_fields']) || !$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | ?> |
| 299 | </div> |
| 300 | </div> |
| 301 | </div> |
| 302 | <?php |
| 303 | |
| 304 | } |
| 305 | |
| 306 | |
| 307 | /** |
| 308 | * layout_div |
| 309 | * |
| 310 | * @param $div |
| 311 | * @param $layout |
| 312 | * @param $field |
| 313 | * |
| 314 | * @return mixed |
| 315 | */ |
| 316 | function layout_div($div, $layout, $field){ |
| 317 | |
| 318 | if(!$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 319 | return $div; |
| 320 | } |
| 321 | |
| 322 | // already in class |
| 323 | if(in_array('-collapsed', explode(' ', $div['class']))){ |
| 324 | return $div; |
| 325 | } |
| 326 | |
| 327 | $div['class'] .= ' -collapsed'; |
| 328 | |
| 329 | return $div; |
| 330 | |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /** |
| 335 | * layout_icons |
| 336 | * |
| 337 | * @param $icons |
| 338 | * @param $layout |
| 339 | * @param $field |
| 340 | * |
| 341 | * @return mixed |
| 342 | */ |
| 343 | function layout_icons($icons, $layout, $field){ |
| 344 | |
| 345 | if(!$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 346 | return $icons; |
| 347 | } |
| 348 | |
| 349 | // replace collapse with edit icon |
| 350 | if(isset($icons['collapse'])){ |
| 351 | $icons['collapse'] = '<div class="acf-layout-collapse"><a class="acf-icon -edit -clear" href="#" data-action="acfe-flexible-modal-edit" aria-label="' . esc_attr__('Toggle layout','acf') . '"></a></div>'; |
| 352 | } |
| 353 | |
| 354 | return $icons; |
| 355 | |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /** |
| 360 | * layout_handle |
| 361 | * |
| 362 | * @param $handle |
| 363 | * @param $layout |
| 364 | * @param $field |
| 365 | * |
| 366 | * @return mixed |
| 367 | */ |
| 368 | function layout_handle($handle, $layout, $field){ |
| 369 | |
| 370 | if(!$field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 371 | return $handle; |
| 372 | } |
| 373 | |
| 374 | $handle['data-action'] = 'acfe-flexible-modal-edit'; |
| 375 | |
| 376 | return $handle; |
| 377 | |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /** |
| 382 | * action_buttons |
| 383 | * |
| 384 | * @param $buttons |
| 385 | * @param $field |
| 386 | * @param $position |
| 387 | * |
| 388 | * @return array|mixed |
| 389 | */ |
| 390 | function action_buttons($buttons, $field, $position){ |
| 391 | |
| 392 | // remove expand/collapse top actions |
| 393 | if($position === 'top' && $field['acfe_flexible_modal_edit']['acfe_flexible_modal_edit_enabled']){ |
| 394 | acfe_unset($buttons, 'expand'); |
| 395 | acfe_unset($buttons, 'collapse'); |
| 396 | } |
| 397 | |
| 398 | return $buttons; |
| 399 | |
| 400 | } |
| 401 | |
| 402 | } |
| 403 | |
| 404 | acf_new_instance('acfe_field_flexible_content_edit'); |
| 405 | |
| 406 | endif; |