From 2679a46b7cde3ca9974341df2a8b14840294eb65 Mon Sep 17 00:00:00 2001 From: nicod_ <nicod@lerebooteux.fr> Date: Thu, 25 May 2023 19:56:28 +0200 Subject: [PATCH] =?UTF-8?q?Fonctions=20g=C3=A9n=C3=A9riques=20pour=20retro?= =?UTF-8?q?uver=20les=20blocktypes=20enfants/parents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blocks_fonctions.php | 19 +++++++++++++++++++ formulaires/editer_blocktype.php | 6 ++---- prive/objets/contenu/blocktype.html | 8 ++++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/blocks_fonctions.php b/blocks_fonctions.php index b7fad01..ff8987f 100644 --- a/blocks_fonctions.php +++ b/blocks_fonctions.php @@ -218,3 +218,22 @@ function blocks_trouver_squelette($identifiant, $force_public = false, $chemin_c return $squelette; } + +function bloctypes_trouver_enfants($id_blocktype) { + return bloctypes_trouver_role($id_blocktype, 'enfant'); +} + +function bloctypes_trouver_parents($id_blocktype) { + return bloctypes_trouver_role($id_blocktype, 'parent'); +} + +function bloctypes_trouver_role($id_blocktype, $role) { + if ( + $id_blocktype + && $role + && ($blocktypes_parents = objet_trouver_liens(['blocktype' => $id_blocktype], ['blocktype' => '*'], ['role' => $role])) + ) { + return array_column($blocktypes_parents, 'id_objet'); + } + return []; +} diff --git a/formulaires/editer_blocktype.php b/formulaires/editer_blocktype.php index a2152a3..ebebaeb 100644 --- a/formulaires/editer_blocktype.php +++ b/formulaires/editer_blocktype.php @@ -164,13 +164,11 @@ function formulaires_editer_blocktype_charger_dist($id_blocktype = 'new', $retou $valeurs = formulaires_editer_objet_charger('blocktype', $id_blocktype, '', $lier_trad, $retour, $config_fonc, $row, $hidden); $valeurs['objets'] = blocks_deserialize($valeurs['objets']); - if ($blocktypes_enfants = objet_trouver_liens(['blocktype' => $id_blocktype], ['blocktype' => '*'], ['role' => 'enfant'])) { - $valeurs['blocktypes_enfants'] = array_column($blocktypes_enfants, 'id_objet'); + if ($valeurs['blocktypes_enfants'] = bloctypes_trouver_enfants($id_blocktype)) { $valeurs['conteneur_enfants'] = 'on'; } - if ($blocktypes_parents = objet_trouver_liens(['blocktype' => $id_blocktype], ['blocktype' => '*'], ['role' => 'parent'])) { - $valeurs['blocktypes_parents'] = array_column($blocktypes_parents, 'id_objet'); + if ($valeurs['blocktypes_parents'] = bloctypes_trouver_parents($id_blocktype)) { $valeurs['conteneur_parents'] = 'on'; } diff --git a/prive/objets/contenu/blocktype.html b/prive/objets/contenu/blocktype.html index 553dccc..46523f5 100644 --- a/prive/objets/contenu/blocktype.html +++ b/prive/objets/contenu/blocktype.html @@ -11,8 +11,8 @@ <B> <p><strong class="label"><:blocktype:champ_conteneur_enfants_label:/> : </strong></p> <ul class="spip"> - <BOUCLE(spip_blocktypes_liens){id_blocktype}{role=enfant}> - <li>#INFO_TITRE{blocktype,#ID_OBJET}</li> + <BOUCLE(DATA) {source tableau, #ID_BLOCKTYPE|bloctypes_trouver_enfants}> + <li>#INFO_TITRE{blocktype,#VALEUR}</li> </BOUCLE> </ul> </B> @@ -20,8 +20,8 @@ <B> <p><strong class="label"><:blocktype:champ_conteneur_parents_label:/> : </strong></p> <ul class="spip"> - <BOUCLE(spip_blocktypes_liens){id_blocktype}{role=parent}> - <li>#INFO_TITRE{blocktype,#ID_OBJET}</li> + <BOUCLE(DATA) {source tableau, #ID_BLOCKTYPE|bloctypes_trouver_parents}> + <li>#INFO_TITRE{blocktype,#VALEUR}</li> </BOUCLE> </ul> </B> -- GitLab