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 $choices = [
['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()
private function buildChoicesArray()
{
$choices = [
$posts_array = [
[
'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"),
'slug' => "the post name",
'ID' => 24
'ID_fr' => 7153,
'ID_nl' => 7157,
],
[
'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()
@ -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) {
$brochureOrderAmount = null;
$documentOrderAmountHtml = null;
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"]) {
$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)) {
$brochureOrderPreviewHtml .= '<li><h3>' . $brochure . '</h3><ul class="days">' . $brochureOrderAmount . '</ul></li>';
if (!empty($documentOrderAmountHtml)) {
$documentOrderPreviewHtml .= '<li><h3>' . $brochure . '</h3><ul class="days">' . $documentOrderAmountHtml . '</ul></li>';
}
}
$brochureOrderPreviewHtml .= '</ul>';
return $brochureOrderPreviewHtml;
$documentOrderPreviewHtml .= '</ul>';
return $documentOrderPreviewHtml;
}
@ -164,14 +148,14 @@ if (class_exists('GF_Field')) {
if (empty($value)) {
return;
}
$str = $this->PrettyListBrochureOrder($value);
$str = $this->PrettyListDocumentOrder($value);
return $str;
}
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());

View File

@ -10,6 +10,7 @@
<?php
$thematique = getPostMainThematique($brochurePost['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 ?>
</p>
</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>
<div class="inputs-container">
<div class="publications-amount-fr">

View File

@ -4,15 +4,16 @@
<fieldset class="field-order-paper-publications">
<?php
// $choices = $this->buildChoices();
$otherPublicationsArray = $this->buildChoicesArray();
?>
<?php foreach ($this->choices as $index => $document) : ?>
<?php foreach ($otherPublicationsArray as $index => $document) : ?>
<?php
$test = get_term(143, 'thematiques');
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
write_log($thematiqueCover);
$documentPost = get_post($document['ID']);
$metadata = wp_get_attachment_metadata($document['ID']);
?>
<div class=" gchoice brochure-order-field">
@ -25,7 +26,7 @@
</p>
</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>
<div class="inputs-container">
<div class="publications-amount-fr">
@ -39,8 +40,8 @@
</div>
<?php if ($document['value']) : ?>
<p class="legend"><?php echo $document['value'] ?></p>
<?php if ($documentPost->post_content) : ?>
<!-- <p class="legend"><?php echo $documentPost->post_content ?></p> -->
<?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_title {
@apply hidden;
@ -182,17 +186,21 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
} */
.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 {
@apply grid justify-end gap-3 items-center;
grid-template-columns: auto 1fr 1fr auto;
@apply grid justify-end gap-3 gap-y-2 items-center;
grid-template-columns: 1fr;
@screen md {
grid-template-columns: auto 1fr 1fr auto;
}
.thematique-tag,
legend {
@apply mt-6;
@apply md:mt-6;
}
.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;
}
.thematique-icon {
@ -203,7 +211,8 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
font-weight: revert !important;
}
.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 {
content: ' ';
@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 {
@apply max-w-screen-lg;