How to replace allowed_values for a select field by external definition? I created a custom content entity, called member, with some fields of which one, called status, is a list appearing in form as a select:  

$fields['status'] = BaseFieldDefinition::create('list_integer')
  -&gt;setLabel(t('Statut'))
  -&gt;setRequired(TRUE)
  -&gt;setSettings(array(
    'allowed_values' =&gt; array(
      0 =&gt; 'Ancien',
      1 =&gt; 'Actif',
      2 =&gt; 'Non renouvelée',
      3 =&gt; 'Renouvelée',
      4 =&gt; 'En attente',
    ),
  ))
  -&gt;setDefaultValue(4)
  -&gt;setDisplayOptions('view', array(
    'label' =&gt; 'above',
    'weight' =&gt; 7,
  ))
  -&gt;setDisplayOptions('form', array(
    'type' =&gt; 'options_select',
    'weight' =&gt; 7,
  ))
  -&gt;setDisplayConfigurable('form', TRUE)
  -&gt;setDisplayConfigurable('view', TRUE);


I'd like to put the definition of the allowed values 'somewhere else' (meaning not directly in the definition of the member entity).
I know I could create another content entity (e.g. possible_status) that I would reference this way:  

$fields['status'] = BaseFieldDefinition::create('entity_reference')
  -&gt;setSetting('target_type', 'possible_status)')


But it seems a bit 'rich' to handle a couple of values...
Is there another way to store the values 'outside' the code defining the member entity?
An include file, a text file, a JSON file I could import?
What would be the best practice for that?  

[EDIT]
I changed for this:  

$fields['status'] = BaseFieldDefinition::create('list_integer')
  -&gt;setLabel(t('Statut'))
  -&gt;setRequired(TRUE)
  -&gt;setSettings(['allowed_values_function' =&gt; 'association_allowed_values_function'])
  -&gt;setDefaultValue(4)


with this in my module:    

function association_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &amp;$cacheable = TRUE) {

  if ($definition['entity_type'] == 'member' &amp;&amp; $definition'field_name' == 'status') {
    $values = [
      0 =&gt; 'Ancien',
      1 =&gt; 'Actif',
      2 =&gt; 'Non renouvelée',
      3 =&gt; 'Renouvelée',
      4 =&gt; 'En attente',
    ];
  }
  return $values;
}


and it works!  

Now, I'd like to move association_allowed_values_function to an include file.   And I don't know how...
Instead of allowed_values you can add a callback to set the allowed values:

  -&gt;setSettings(['allowed_values_function' =&gt; 'callback_allowed_values_function'])


The callback:

function callback_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &amp;$cacheable = TRUE) {
  if (isset($entity) &amp;&amp; ($entity-&gt;bundle() == 'not_a_programmer')) {
    $values = [
      1 =&gt; 'One',
      2 =&gt; 'Two',
    ];
  }
  else {
    $values = [
      'Group 1' =&gt; [
        0 =&gt; 'Zero',
        1 =&gt; 'One',
      ],
      'Group 2' =&gt; [
        2 =&gt; 'Two',
      ],
    ];
  }

  return $values;
}


You can get the allowed values from a text file or put the callback in an include file.

For more information see options.api.php



A different approach might be to store the allowed values in config, for which there is a bundle specific base field override, see How to easily alter an entity&#39;s base field definition per bundle. Then you can manage the allowed values list in a yaml file of an exported config.