Drupal 8 - disable form field

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 viewed 97 times. First hit: 24-Nov-2017 10:23:44
Share email, Google+, Twitter, Facebook.
comments powered by Disqus
Table