buildChoices(); // } private function buildChoices() { $brochures_query = new WP_Query(array( 'post_type' => 'brochures', 'posts_per_page' => -1, 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'date', 'meta_key' => 'brochure_pdf', 'meta_value' => false, 'meta_compare' => '!=', )); $choices = []; $sortedBrochuresPosts = sort_posts_per_thematiques_priority($brochures_query); foreach ($sortedBrochuresPosts->posts as $key => $post) { array_push($choices, ['text' => $post->post_title, 'slug' => $post->post_name, 'ID' => $post->ID]); } $this->choices = $choices; } public function get_form_editor_field_title() { return esc_attr__('Commande de publications papier', 'txtdomain'); } public function get_form_editor_button() { return [ 'group' => 'advanced_fields', 'text' => $this->get_form_editor_field_title(), ]; } public function get_form_editor_field_icon() { return 'gform-icon--multi-select'; } public function get_form_editor_field_settings() { return [ 'label_setting', 'choices_setting', 'description_setting', 'rules_setting', 'error_message_setting', 'css_class_setting', 'conditional_logic_field_setting' ]; } // public $choices = [ // ['text' => 'Publication 1'], // ['text' => 'Publication 2'], // ['text' => 'Publication 3'], // ]; public function is_value_submission_array() { return true; } public function get_field_input($form, $value = '', $entry = null) { $this->buildChoices(); $form_id = $form['id']; $id = $this->id; ob_start(); include 'template-form-order-paper.php'; $table = ob_get_clean(); return $table; } private function translateValueArray($value) { $this->buildChoices(); $table_value = []; $counter = 0; foreach ($this->choices as $brochure) { $table_value[$brochure['text']]['quantity_fr'] = $value[$counter] ?? 0; $table_value[$brochure['text']]['quantity_nl'] = $value[$counter + 1] ?? 0; $counter += 2; } return $table_value; } public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) { if (empty($value)) { $value = ''; } else { $table_value = $this->translateValueArray($value); $value = serialize($table_value); } return $value; } private function PrettyListBrochureOrder($value) { $brochureOrderPreviewHtml = '