Home Account

Drupal 8 - disable form field

2017-11-24 12:22 dennis iversen

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;

    }
}

This page has been requested 7395 times