---
title: "Drupal 8: Form API - Weight Fields"
url: "https://michalak.world/posts/drupal-8-form-api-weighted-fields/"
description: "Custom weights on Form API Fields"
summary: "Custom weights on Form API fields."
date: 2019-03-14
lastmod: 2026-08-19
tags: ["Drupal","Drupal 8","Form API","Drupal Commerce","Drupal Development","Purchase Orders"]
section: "posts"
author: "Michael Michalak"
site: "https://michalak.world/"
---

# Drupal 8: Form API - Weight Fields

Custom weights on Form API Fields

Currently, I am working on a custom form that generates products on the fly for a custom purchase order implementation.  

For this Drupal 8 commerce website, the product variations have a required weight field which was needed in the custom form.  

Here is an example of the weight field. 
```
    $form['product']['weight'] = array(
      '#type' => 'physical_measurement',
      '#title' => t('Weight'),
      '#measurement_type' => 'weight',
       //the default field is required and must be an array.
      '#default_value' => ['number' => 2.00, 'unit' => 'oz'], 
    );
```

