From bb5a5b65f65efb32e4afd7b79a691fcc396453d0 Mon Sep 17 00:00:00 2001 From: nicod_ <nicod@lerebooteux.fr> Date: Fri, 17 Jan 2025 01:41:26 +0100 Subject: [PATCH] refactor: changement de signature, doc, rangement --- blocks_fonctions.php | 2 +- inc/blocks.php | 35 ++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/blocks_fonctions.php b/blocks_fonctions.php index 348ac7c..8ebc8af 100644 --- a/blocks_fonctions.php +++ b/blocks_fonctions.php @@ -181,7 +181,7 @@ function generer_TITRE_BLOCK($id_block): string { 'spip_blocks', 'id_block = ' . (int)$id_block )) { - $titre = blocktype_info('titre', $infos['blocktype']); + $titre = blocktype_info($infos['blocktype'], 'titre'); if ($infos['id_objet'] && $infos['objet']) { $titre = generer_objet_info($infos['id_objet'], $infos['objet'], 'titre') . ' - ' . $titre . ' #' . $infos['rang_lien']; } diff --git a/inc/blocks.php b/inc/blocks.php index 4dd8655..dc6a32f 100644 --- a/inc/blocks.php +++ b/inc/blocks.php @@ -59,7 +59,7 @@ function blocktypes_lister_types(bool $exclure_ignores = true): array { $yaml_data['titre'] = _T_ou_typo($yaml_data['titre']); $yaml_data['identifiant'] = $blocktype; $yaml_data['description'] = _T_ou_typo($yaml_data['description']); - $yaml_data['icone'] = isset($yaml_data['icone']) ? blocktype_find_icone_path($yaml_data['icone']) : ''; + $yaml_data['icone'] = isset($yaml_data['icone']) ? _blocktype_find_icone_path($yaml_data['icone']) : ''; $liste_blocktypes[$blocktype] = $yaml_data; } @@ -93,10 +93,10 @@ function blocktypes_lister_types(bool $exclure_ignores = true): array { /** * Retrouver l'icone d'un blocktype, la réduire à 16 px * - * @param string $blocktype + * @param string $blocktype Type de bloc (identifiant) * @return string chemin **/ -function blocktype_find_icone_path(string $blocktype): string { +function _blocktype_find_icone_path(string $blocktype): string { static $cache; if (isset($cache[$blocktype])) { return $cache[$blocktype]; @@ -121,6 +121,19 @@ function blocktype_find_icone_path(string $blocktype): string { return $chemin; } +/** + * Obtenir une info de la config d'un block + * + * @param string $blocktype Type de bloc (identifiant) + * @param string $config Clé de la config à retrouver + * @return string|array|null + */ +function blocktype_info(string $blocktype, string $config) { + $blocktypes = blocktypes_lister_types(); + + return $blocktypes[$blocktype][$config] ?? null; +} + /** * Obtenir les saisies d'un block * @@ -143,18 +156,6 @@ function block_get_saisies(int $id_block): array { return $saisies; } -/** - * Obtenir une info de la config d'un block - * - * @param string $blocktype - * @return string|array|null - */ -function blocktype_info(string $config, string $blocktype) { - $blocktypes = blocktypes_lister_types(); - - return $blocktypes[$blocktype][$config] ?? null; -} - /** * Retourner un tableau des valeurs saisies * @@ -177,7 +178,7 @@ function block_get_valeurs(array $saisies, array $valeurs): array { /** * Chercher le squelette correspondant à un block par son identifiant * - * @param string $blocktype Identifiant du type de block + * @param string $blocktype Type de bloc (identifiant) * @param bool $force_public Forcer une recherche du squelette public * @param bool $chemin_complet Retourne le chemin complet du squelette * @param bool $dist Retourne le squelette par défaut (dist)) @@ -266,7 +267,7 @@ function bloctypes_trouver_parents($blocktype): array { /** * Calculer une liste de types de blocks enfants ou parents en fonction du rôle - * @param string $blocktype + * @param string $blocktype Type de bloc (identifiant) * @param string $role * @return array */ -- GitLab