How to create a new entity with default values if not passed? Hello everyone how are you?
I created a new configEntity called Modal with 3 fields:

Label
Body
Auto Open

To create a new Modal I'm using this code:
$modal = \Drupal::entityTypeManager()-&gt;getStorage('modal')-&gt;create();

$modal-&gt;setLabel('Modal Title');
$modal-&gt;setBody('Modal Content');
$modal-&gt;setAutoOpen(TRUE);
$modal-&gt;save();

OK! It works!
But now I don't want to pass &quot;auto-open&quot; and I this value with TRUE as default. Like this:
$modal = \Drupal::entityTypeManager()-&gt;getStorage('modal')-&gt;create();
        
$modal-&gt;setLabel('Modal Title');
$modal-&gt;setBody('Modal Content');
$modal-&gt;save();

Note that there is no &quot;Auto-Open&quot; and it inserts a new Modal with &quot;auto-open&quot; = FALSE
My goal is; if you don't pass &quot;auto-open&quot; this field is filled with TRUE by default.
Do you know how can we do this? 
Thank you so much, everyone
For entities in general, set default values by adding preCreate() to your entity class:
  /**
   * {@inheritdoc}
   */
  public static function preCreate(EntityStorageInterface $storage_controller, array &amp;$values) {
    parent::preCreate($storage_controller, $values);
    $values += [
      'auto_open' =&gt; TRUE,
    ];
  }


In this specific case, define a class property with the same name as the field, which defaults to TRUE:
  /**
   * Auto Open.
   *
   * @var bool
   */
  protected $auto_open = TRUE;