Funzione drupaldemo_form_alter()

Da admin, 10 Giugno, 2026

In drupaldemo.module

/**
* Implementa hook_form_alter().
*/
function drupaldemo_form_alter(
array &$form,
FormStateInterface $form_state,
string $form_id
): void {

// Interviene solo sui form di creazione e modifica del content type Documento.
if (!in_array($form_id, ['node_documento_form', 'node_documento_edit_form'], TRUE)) {
return;
}


$current_user = \Drupal::currentUser();
// dump($current_user);
// exit();

// Verifica la presenza del ruolo editor.
if (in_array('content_editor', $current_user->getRoles(), TRUE)) {

// Aggiunge un testo introduttivo sopra al form.
$form['drupaldemo_intro'] = [
'#type' => 'markup',
'#markup' => '<p><strong>Nota:</strong> compilare con attenzione i dati del documento!</p>',
'#weight' => -100,
];

// Rende non modificabile il campo Livello.
if (isset($form['field_livello'])) {
$form['field_livello']['#disabled'] = TRUE;
}

if (isset($form['field_argomenti'])) {
$form['field_argomenti']['#access'] = FALSE;
}

}


}