Admin.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Helpers\Form\Template\Utils; |
| 4 | |
| 5 | use Give\Form\Template; |
| 6 | use Give\FormAPI\Form\Field; |
| 7 | use Give\FormAPI\Section; |
| 8 | use Give\Helpers\Form\Template as FormTemplateUtils; |
| 9 | use WP_Post; |
| 10 | |
| 11 | class Admin |
| 12 | { |
| 13 | /** |
| 14 | * Render template setting in form metabox. |
| 15 | * |
| 16 | * @since 2.7.0 |
| 17 | * |
| 18 | * @param Template $template |
| 19 | * |
| 20 | * @return string |
| 21 | * @global WP_Post $post |
| 22 | */ |
| 23 | public static function renderMetaboxSettings($template) |
| 24 | { |
| 25 | global $post; |
| 26 | |
| 27 | ob_start(); |
| 28 | |
| 29 | $saveOptions = FormTemplateUtils::getOptions($post->ID, $template->getID()); |
| 30 | |
| 31 | /* @var Section $option */ |
| 32 | foreach ($template->getOptions()->sections as $group) { |
| 33 | printf( |
| 34 | '<div class="give-row %1$s">', |
| 35 | $group->id |
| 36 | ); |
| 37 | |
| 38 | printf( |
| 39 | '<div class="give-row-head"> |
| 40 | <button type="button" class="give-handlediv" aria-expanded="true"> |
| 41 | <span class="toggle-indicator"/> |
| 42 | </button> |
| 43 | <h2><span>%1$s</span></h2> |
| 44 | </div>', |
| 45 | $group->name |
| 46 | ); |
| 47 | |
| 48 | echo '<div class="give-row-body">'; |
| 49 | |
| 50 | /* @var Field $field */ |
| 51 | foreach ($group->fields as $field) { |
| 52 | $field = $field->toArray(); |
| 53 | if (isset($saveOptions[$group->id][$field['id']])) { |
| 54 | $field['attributes']['value'] = $saveOptions[$group->id][$field['id']]; |
| 55 | } |
| 56 | |
| 57 | $field['id'] = "{$template->getID()}[{$group->id}][{$field['id']}]"; |
| 58 | |
| 59 | give_render_field($field); |
| 60 | } |
| 61 | |
| 62 | echo '</div></div>'; |
| 63 | } |
| 64 | |
| 65 | return ob_get_clean(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 |