Home Account

Drupal 8 - disable form field

24-Nov-2017 12:22:30 dennis

Tags: drupal

Use hook_form_alter

E.g. for a module called xmljob:

function xmljob_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
    if ($form_id == "node_jobs_edit_form") {       
        $form['field_job_posted_to_sharepoint']['#attributes']['disabled'][] = 'disabled';
        $form['field_job_posted_to_sharepoint']['#access'] = false;

    }
}