I am using drupal 8, I have an Entity, I want to add a hidden type field in Entity Form. How I can add hidden field type? like below
<form>
<input type='hidden' name='my_hidden' />
</form>
Code Generating Form is as below:
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
{
$fields = parent::baseFieldDefinitions($entity_type);
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Timeslot entity.'))
->setReadOnly(TRUE);
return $fields;
}
There are two steps to make a field hidden in drupal 8 entity forms.
If you want to make an existing field hidden you may alter the form and update that field as
$form['your_field_name']['widget'][0]['value']['#type'] = 'hidden';
You can use https://www.drupal.org/project/field_hidden and by enabling this module, Select the 'Hidden field' widget for a field in the entity type's 'Manage form display' dialogue.