Custom validation rules for content entity fields
list_string can have an allowed_values_callback instead of a list of allowed values, that allows you to return a dynamic list from that callback.

See callback_allowed_values_function(), which has pretty good documentation, that we've refined over multiple issues.

Make sure you're aware of the rules and limitations of what you can return.. for example that not passing an entity should always return all allowed values and passing one it can only limit those and not add more. And that returning new allowed values is not a problem, but not returning them anymore can be problematic as you might end up with data in your database that is no longer valid. The UI doesn't allow you to do that, for example.