interfaces
1 year ago
traits
1 year ago
action-factory.php
1 year ago
base-api-action.php
1 year ago
create-tags-action.php
1 year ago
get-categories-action.php
1 year ago
get-categories-interests-action.php
1 year ago
get-fields-action.php
1 year ago
get-lists-action.php
1 year ago
put-member-in-list-action.php
1 year ago
get-fields-action.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Modules\Actions_V2\Mailchimp\Api; |
| 4 | |
| 5 | use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 6 | use JFB_Modules\Actions_V2\Mailchimp\Api\Base_Api_Action; |
| 7 | use JFB_Modules\Actions_V2\Mailchimp\Api\interfaces\List_Interface; |
| 8 | use JFB_Modules\Actions_V2\Mailchimp\Api\traits\List_Trait; |
| 9 | |
| 10 | class Get_Fields_Action extends Base_Api_Action implements List_Interface { |
| 11 | |
| 12 | use List_Trait; |
| 13 | |
| 14 | protected $method = 'GET'; |
| 15 | |
| 16 | public function action_endpoint() { |
| 17 | return 'lists/{list_id}/merge-fields?count=999'; |
| 18 | } |
| 19 | |
| 20 | public function generate_fields(): \Generator { |
| 21 | $response = $this->get_response_body(); |
| 22 | |
| 23 | if ( empty( $response['merge_fields'] ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | foreach ( $response['merge_fields'] as $field ) { |
| 28 | yield array( |
| 29 | 'value' => $field['tag'], |
| 30 | 'label' => $field['name'], |
| 31 | 'required' => $field['required'], |
| 32 | ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | } |
| 37 |