From a6120024bbd2759cbf7b4ab3a2e7d277d6b444ea Mon Sep 17 00:00:00 2001 From: nicod_ <nicod@lerebooteux.fr> Date: Thu, 23 Jan 2025 19:43:29 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20Toujours=20charger=20le=20block,=20m?= =?UTF-8?q?=C3=AAme=20sans=20saisie=20ou=20valeurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blocks_fonctions.php | 113 +++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/blocks_fonctions.php b/blocks_fonctions.php index 75c7702..d15a446 100644 --- a/blocks_fonctions.php +++ b/blocks_fonctions.php @@ -52,77 +52,74 @@ function balise_GENERER_BLOCK_dist($p) { * @return string */ function _block_charger_block(int $id_block): string { - $html = ''; $where = ['id_block = ' . $id_block]; if (!test_espace_prive()) { $where[] = 'statut = ' . sql_quote('publie'); } $saisies = block_get_saisies($id_block); $valeurs = blocks_deserialize(sql_getfetsel('valeurs', 'spip_blocks', $where)); - if ($saisies && $valeurs) { - $contexte = array_merge( - [ - 'id_block' => $id_block, - ], - block_get_valeurs($saisies, $valeurs) - ); - $html = recuperer_fond('inclure/block', $contexte); - - if ($blocs_enfants = sql_allfetsel( - 'id_block, blocktype, valeurs', - 'spip_blocks', - 'objet="block" and id_objet = ' . $id_block - )) { - $html_enfants = ''; - foreach ($blocs_enfants as $bloc_enfant) { - $contexte = array_merge( - [ - 'id_block' => $bloc_enfant['id_block'], - ], - block_get_valeurs( - blocktype_info($bloc_enfant['blocktype'], 'saisies'), - blocks_deserialize($bloc_enfant['valeurs']) - ) - ); - if (test_espace_prive()) { - $squelette = 'prive/squelettes/inclure/block_objet'; - $recuperer_fond_options = ['ajax' => 'block-' . $bloc_enfant['id_block']]; - } else { - $squelette = 'inclure/block'; - $recuperer_fond_options = []; - } - $html_enfants .= recuperer_fond( - $squelette, - $contexte, - $recuperer_fond_options - ); - } - if (str_contains($html, '<!--blocks-->')) { - $html = str_replace('<!--blocks-->', $html_enfants, $html); - } else { - $html .= $html_enfants; - } - } + $contexte = array_merge( + [ + 'id_block' => $id_block, + ], + block_get_valeurs($saisies, $valeurs ?? []) + ); + + $html = recuperer_fond('inclure/block', $contexte); - // Ajouter un block - if (test_espace_prive() && bloctype_trouver_enfants(block_get_blocktype($id_block))) { - $html .= recuperer_fond( - 'prive/squelettes/inclure/block_objet', + if ($blocs_enfants = sql_allfetsel( + 'id_block, blocktype, valeurs', + 'spip_blocks', + 'objet="block" and id_objet = ' . $id_block + )) { + $html_enfants = ''; + foreach ($blocs_enfants as $bloc_enfant) { + $contexte = array_merge( [ - 'objet' => 'block', - 'id_objet' => $id_block, - // 'id_block' => 'new', - 'blocktype_parent' => block_get_blocktype($id_block), - 'edit_bloc' => 1, + 'id_block' => $bloc_enfant['id_block'], ], - [ - 'ajax' => 'new_block-' . $id_block, - ] + block_get_valeurs( + blocktype_info($bloc_enfant['blocktype'], 'saisies'), + blocks_deserialize($bloc_enfant['valeurs']) ?? [] + ) + ); + if (test_espace_prive()) { + $squelette = 'prive/squelettes/inclure/block_objet'; + $recuperer_fond_options = ['ajax' => 'block-' . $bloc_enfant['id_block']]; + } else { + $squelette = 'inclure/block'; + $recuperer_fond_options = []; + } + $html_enfants .= recuperer_fond( + $squelette, + $contexte, + $recuperer_fond_options ); } + if (str_contains($html, '<!--blocks-->')) { + $html = str_replace('<!--blocks-->', $html_enfants, $html); + } else { + $html .= $html_enfants; + } + } - //} + // Ajouter un block + if (test_espace_prive() && bloctype_trouver_enfants(block_get_blocktype($id_block))) { + $html .= recuperer_fond( + 'prive/squelettes/inclure/block_objet', + [ + 'objet' => 'block', + 'id_objet' => $id_block, + // 'id_block' => 'new', + 'blocktype_parent' => block_get_blocktype($id_block), + 'edit_bloc' => 1, + ], + [ + 'ajax' => 'new_block-' . $id_block, + ] + ); + } return $html; } -- GitLab