Why is BaseFieldDefinition::getDisplayOptions($display_context) returning NULL I'm trying to get the weight of each field (of a form) in its display.

$fields = $entityManager-&gt;getFieldDefinitions($entity_type, $bundle);

foreach ($fields as $field_name =&gt; $field_definition) {
  $field_definition-&gt;getDisplayOptions('form'); //returns NULL
}


This returns NULL. $field_definition definitely has stuff inside of it. any ideas?
The getFieldDefinitions() method returns NULL if the field is not displayed. From the docs:


  Return value
  
  array|null The array of display options for the field, or NULL if the
  field is not displayed.


The code below is responsible for returning the correct value:

  /**
   * {@inheritdoc}
   */
  public function getDisplayOptions($display_context) {
    return isset($this-&gt;definition['display'][$display_context]['options']) ? $this-&gt;definition['display'][$display_context]['options'] : NULL;
  }


As you can see the $this-&gt;definition['display'][$display_context]['options'] array has to be set. If it isn't set the method returns NULL.