Form Alter DRUPAL 8

22 Apr 2020

How to form alter of node page in DRUPAL 8

Published On: Wed, 04/22/2020 - 22:13

I want to change select list value in my state field so we follow the step My content type is 'project' so we can get the form id as 'node_project_form' I have a feild 'state' in my content type so field machine name is 'field_state'

function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
	$dropdown_array = array('DL'=>'Delhi');
	if ($form_id == 'node_project_form') {
		$form['field_state']['widget'] = array(     
		 '#type' => 'select',