@ -54,6 +54,42 @@ function formulaires_editer_blocktype_saisies_dist($id_blocktype = 'new', $retou
],
],
[
'saisie' => 'case',
'options' => [
'nom' => 'conteneur_enfants',
'label_case' => _T('blocktype:champ_conteneur_enfants_label'),
],
],
[
'saisie' => 'blocktypes',
'options' => [
'nom' => 'blocktypes_enfants',
'label' => _T('blocktype:champ_blocktypes_enfants_label'),
'afficher_si' => '@conteneur_enfants@ == "on"',
'multiple' => 'oui',
'titre_court' => 'oui',
'exclus' => [$id_blocktype],
],
],
[
'saisie' => 'case',
'options' => [
'nom' => 'conteneur_parents',
'label_case' => _T('blocktype:champ_conteneur_parents_label'),
],
],
[
'saisie' => 'blocktypes',
'options' => [
'nom' => 'blocktypes_parents',
'label' => _T('blocktype:champ_blocktypes_parents_label'),
'afficher_si' => '@conteneur_parents@ == "on"',
'multiple' => 'oui',
'titre_court' => 'oui',
'exclus' => [$id_blocktype],
],
],
[
'saisie' => 'input',
'options' => [
@ -61,7 +97,6 @@ function formulaires_editer_blocktype_saisies_dist($id_blocktype = 'new', $retou
'obligatoire' => 'oui',
'label' => _T('blocktype:champ_identifiant_label'),
'explication' => _T('blocktype:champ_identifiant_explication'),
],
],
];
@ -128,6 +163,17 @@ function formulaires_editer_blocktype_identifier_dist($id_blocktype = 'new', $re
function formulaires_editer_blocktype_charger_dist($id_blocktype = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$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');
$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');
$valeurs['conteneur_parents'] = 'on';
}
$valeurs['saisies'] = call_user_func_array('formulaires_editer_blocktype_saisies_dist', func_get_args());
return $valeurs;
}
@ -181,11 +227,40 @@ function formulaires_editer_blocktype_verifier_dist($id_blocktype = 'new', $reto
*
*/
function formulaires_editer_blocktype_traiter_dist($id_blocktype = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$creation = (int)$id_blocktype ? false : true;
set_request('objets', blocks_serialize(_request('objets')));
$retours = formulaires_editer_objet_traiter('blocktype', $id_blocktype, '', $lier_trad, $retour, $config_fonc, $row, $hidden);
if (!(int)$id_blocktype) {
if ($id_blocktype = $retours['id_blocktype']) {
// mettre à jour les rôles
objet_dissocier(['blocktype' => $id_blocktype], ['blocktype' => '*'], ['role' => 'enfant']);
if ($blocktypes_enfants = _request('blocktypes_enfants')) {
foreach ($blocktypes_enfants as $blocktype_enfant) {
objet_associer(['blocktype' => $id_blocktype], ['blocktype' => $blocktype_enfant], ['role' => 'enfant']);
}
}
objet_dissocier(['blocktype' => $id_blocktype], ['blocktype' => '*'], ['role' => 'parent']);
if ($blocktypes_parents = _request('blocktypes_parents')) {
foreach ($blocktypes_parents as $blocktype_parent) {
objet_associer(['blocktype' => $id_blocktype], ['blocktype' => $blocktype_parent], ['role' => 'parent']);
objet_associer(['blocktype' => $blocktype_parent], ['blocktype' => $id_blocktype], ['role' => 'enfant']);
}
}
// réassigner le role enfant pour les roles parents existants
if ($blocktypes_parents = objet_trouver_liens(['blocktype' => '*'], ['blocktype' => '*'], ['role' => 'parent'])) {
foreach ($blocktypes_parents as $blocktype_parent) {
objet_associer(['blocktype' => $blocktype_parent['id_objet']], ['blocktype' => $blocktype_parent['id_blocktype']], ['role' => 'enfant']);
}
}
}
if ($creation) {
// en cas de création d'un type de block, rediriger vers la configuration des champs
$retours['redirect'] = generer_url_ecrire('blocktype_edit_champs', 'id_blocktype=' . $retours['id_blocktype']);
}
return $retours;
}