Setting a field value on node save I have a note type 'team' with a body field and a checkbox field (checked by default). I want to automatically check the box on save IF there is content in the body field. Is there a way to do that programmatically?
Yes, this is possible with hook_ENTITY_TYPE_presave

/**
 * Auto check checkbox whatever, etc, etc.
 *
 * Implements hook_ENTITY_TYPE_presave()
 */
function my_module_node_presave($entity) {
  if ($entity-&gt;bundle() == 'team') {
    // Check if there is content in the body field.
    if (!empty($entity-&gt;body-&gt;value)) {
      // Set checkbox field.
      $entity-&gt;set('my_checkbox_field', 1);
    }
  }
}


Then, you'll probably want to remove the checkbox field from your form display on the Manage Form Display screen and also update the field settings so it's not checked by default since you'll be programmatically checking it if your body field has a value.