updating form functionnality

This commit is contained in:
Antoine M 2024-05-21 10:45:26 +02:00
parent b176cfbe63
commit 66b1a36a1d
5 changed files with 106 additions and 59 deletions

View File

@ -0,0 +1,47 @@
<?php
foreach ($testArray as $index => $document) : ?>
<?php
$test = get_term(143, 'thematiques');
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
?>
<div class=" gchoice brochure-order-field">
<div class="thematique-tag thematique-tag--general">
<?php if ($thematiqueCover && $thematiqueCover['icon']) : ?>
<img class="thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
<?php endif; ?>
<p>
<?php echo __("Autre", "homegrade-theme__texte-fonctionnel") ?>
</p>
</div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $document['text'] ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container">
<div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
<div class="publications-amount publications-amount-nl">
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
</div>
<?php if ($document['value']) : ?>
<p class="legend"><?php echo $document['value'] ?></p>
<?php endif; ?>
</div>
<div class="gchoice brochure-order-field">
</div>
<?php endforeach; ?>

View File

@ -5,46 +5,30 @@ if (class_exists('GF_Field')) {
{ {
public $type = 'order_documents_list'; public $type = 'order_documents_list';
public $choices = [ private function buildChoicesArray()
['text' => 'Synthèse des primes'],
['text' => 'Publication 2'],
['text' => 'Publication 3'],
];
// public $choices = [
// [
// 'text' => 'Synthèse des primes',
// 'slug' => "the post name",
// 'ID' => 24
// ],
// [
// 'text' => 'Document 2',
// 'slug' => "the post name",
// 'ID' => 24
// ],
// ];
private function buildChoices()
{ {
$choices = [ $posts_array = [
[ [
'text' => 'La synthèse des primes', 'text' => 'La synthèse des primes',
'description' => __("Ce document informe sur les incitants financiers à lachat et à la rénovation des logements en Région de Bruxelles-Capitale, dont les primes RENOLUTION, le crédit ECORENO, la subvention petit patrimoine, la prime gaz, les certificats verts...", "homegrade-theme__texte-fonctionnel"), 'ID_fr' => 7153,
'slug' => "the post name", 'ID_nl' => 7157,
'ID' => 24
], ],
[
'text' => 'Document 2',
'slug' => "the post name",
'ID' => 24
],
]; ];
$currentLang = apply_filters('wpml_current_language', null);
$this->choices = $choices;
foreach ($posts_array as $post) {
$id = $currentLang === 'nl' ? $post['ID_nl'] : $post['ID_fr'];
$choices[] = [
'title' => get_the_title($id),
'ID' => $id,
];
}
return $choices;
} }
public function get_form_editor_field_title() public function get_form_editor_field_title()
@ -125,31 +109,31 @@ if (class_exists('GF_Field')) {
} }
private function PrettyListBrochureOrder($value) private function PrettyListDocumentOrder($value)
{ {
$brochureOrderPreviewHtml = '<ul>'; $documentOrderPreviewHtml = '<ul>';
foreach ($value as $brochure => $quantities) { foreach ($value as $brochure => $quantities) {
$brochureOrderAmount = null; $documentOrderAmountHtml = null;
if ($quantities["quantity_fr"]) { if ($quantities["quantity_fr"]) {
$brochureOrderAmount .= '<li>' . __("Quantité FR: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_fr"] . '</span></li>'; $documentOrderAmountHtml .= '<li>' . __("Quantité FR: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_fr"] . '</span></li>';
} }
if ($quantities["quantity_nl"]) { if ($quantities["quantity_nl"]) {
$brochureOrderAmount .= '<li>' . __("Quantité NL: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_nl"] . '</span></li>'; $documentOrderAmountHtml .= '<li>' . __("Quantité NL: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_nl"] . '</span></li>';
} }
if (!$brochureOrderAmount) continue; if (!$documentOrderAmountHtml) continue;
if (!empty($brochureOrderAmount)) { if (!empty($documentOrderAmountHtml)) {
$brochureOrderPreviewHtml .= '<li><h3>' . $brochure . '</h3><ul class="days">' . $brochureOrderAmount . '</ul></li>'; $documentOrderPreviewHtml .= '<li><h3>' . $brochure . '</h3><ul class="days">' . $documentOrderAmountHtml . '</ul></li>';
} }
} }
$brochureOrderPreviewHtml .= '</ul>'; $documentOrderPreviewHtml .= '</ul>';
return $brochureOrderPreviewHtml; return $documentOrderPreviewHtml;
} }
@ -164,14 +148,14 @@ if (class_exists('GF_Field')) {
if (empty($value)) { if (empty($value)) {
return; return;
} }
$str = $this->PrettyListBrochureOrder($value); $str = $this->PrettyListDocumentOrder($value);
return $str; return $str;
} }
public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
{ {
return $this->PrettyListBrochureOrder($value); return $this->PrettyListDocumentOrder($value);
} }
} }
GF_Fields::register(new OrderDocumentList()); GF_Fields::register(new OrderDocumentList());

View File

@ -10,6 +10,7 @@
<?php <?php
$thematique = getPostMainThematique($brochurePost['ID']); $thematique = getPostMainThematique($brochurePost['ID']);
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id); $thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id);
$brochure_pdf_link = get_field('brochure_pdf', $brochurePost['ID']);
?> ?>
@ -22,7 +23,9 @@
<?php echo $thematique->name ?> <?php echo $thematique->name ?>
</p> </p>
</div> </div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $brochurePost['text'] ?></legend>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $brochure_pdf_link['title'] ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank"><?php echo __("Voir la brochure", "homegrade-theme__texte-fonctionnel") ?></a> <a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank"><?php echo __("Voir la brochure", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container"> <div class="inputs-container">
<div class="publications-amount-fr"> <div class="publications-amount-fr">

View File

@ -4,15 +4,16 @@
<fieldset class="field-order-paper-publications"> <fieldset class="field-order-paper-publications">
<?php <?php
// $choices = $this->buildChoices();
$otherPublicationsArray = $this->buildChoicesArray();
?> ?>
<?php foreach ($this->choices as $index => $document) : ?>
<?php foreach ($otherPublicationsArray as $index => $document) : ?>
<?php <?php
$test = get_term(143, 'thematiques');
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143"); $thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
$documentPost = get_post($document['ID']);
write_log($thematiqueCover); $metadata = wp_get_attachment_metadata($document['ID']);
?> ?>
<div class=" gchoice brochure-order-field"> <div class=" gchoice brochure-order-field">
@ -25,7 +26,7 @@
</p> </p>
</div> </div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $document['text'] ?></legend> <legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $documentPost->post_title ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a> <a class="preview-brochure" href="<?php echo get_the_permalink($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container"> <div class="inputs-container">
<div class="publications-amount-fr"> <div class="publications-amount-fr">
@ -39,8 +40,8 @@
</div> </div>
<?php if ($document['value']) : ?> <?php if ($documentPost->post_content) : ?>
<p class="legend"><?php echo $document['value'] ?></p> <!-- <p class="legend"><?php echo $documentPost->post_content ?></p> -->
<?php endif; ?> <?php endif; ?>

View File

@ -89,6 +89,10 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
} }
} }
legend.gfield_label + .gfield_description {
@apply !pb-4;
}
.gform_wrapper { .gform_wrapper {
.gform_title { .gform_title {
@apply hidden; @apply hidden;
@ -182,17 +186,21 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
} */ } */
.field-order-paper-publications { .field-order-paper-publications {
@apply !grid gap-x-12 gap-y-2; @apply !grid gap-x-12 gap-y-6 md:gap-y-2;
.brochure-order-field { .brochure-order-field {
@apply grid justify-end gap-3 items-center; @apply grid justify-end gap-3 gap-y-2 items-center;
grid-template-columns: auto 1fr 1fr auto; grid-template-columns: 1fr;
@screen md {
grid-template-columns: auto 1fr 1fr auto;
}
.thematique-tag, .thematique-tag,
legend { legend {
@apply mt-6; @apply md:mt-6;
} }
.thematique-tag { .thematique-tag {
@apply !py-1 !px-4 !rounded-lg mr-4 flex items-center shrink-0; @apply !py-1 !px-4 !rounded-lg mr-4 flex items-center shrink-0 w-fit;
line-height: 1.7; line-height: 1.7;
} }
.thematique-icon { .thematique-icon {
@ -203,7 +211,8 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
font-weight: revert !important; font-weight: revert !important;
} }
.preview-brochure { .preview-brochure {
@apply !text-neutral-700 flex justify-center items-center w-fit mx-auto; @apply !text-neutral-700 flex justify-center items-center w-fit md:mx-auto;
&:after { &:after {
content: ' '; content: ' ';
@apply w-4 h-4 block ml-3 bg-no-repeat bg-center bg-contain; @apply w-4 h-4 block ml-3 bg-no-repeat bg-center bg-contain;
@ -233,6 +242,9 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
} }
} }
} }
.homegrade-delivering .gfield_description {
@apply !text-secondary py-2;
}
#gform_wrapper_18 { #gform_wrapper_18 {
@apply max-w-screen-lg; @apply max-w-screen-lg;