Drupal 8 hide field and set default value

Note Statistics

Note Statistics

  • Viewed 61 times
  • Bookmarked 2 times
  • 2 Grateful readers
Wed, 12/18/2019 - 21:00

Define hook_form_alter

MODULE_NAME_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) {
    $is_my_entity_form = in_array( "my-entity-form", $context['form']['#attributes']['class']) ;
   if($is_note_entity_form && $field_name == 'target-field') {
    $element['#default_value'] = true;
    $element['#access'] = false;
  }
}
Authored by
Tags