Dynamic allowed values list How  to display dynamic allowed values list in drupal 8?

In drupal 6 while creating cck select list, I written php code instead of entering allowed values. The sample code of drupal 6 is as follows :

$query = db_query("SELECT distinct field_x_value as x FROM {node} n, {content_type_y} ctdr , {content_field_x} cfer WHERE n.nid = ctdr.nid and cfer.nid = ctdr.nid and field_x_value is not null and field_user_state_value = %d and n.status = %d and field_environment_value = %d", $user-&gt;user_state, 1, $environment);


How to do the same functionality in drupal 8?
It's not possible to set it in the UI, but it's still possible through code.

If you check the exported configuration for your field, you can see that it has an allowed_values_callback property. Create a custom module, create a function that returns the allowed values, set that property in config and then import the configuration again. Or use drush cedit or a similar tool.