How can I assign a field to a entity bundle.

Hello I have create a module, I have create also the file,

I can assign the field with the UI.

But what I’m looking is to assign the field to the bundles programatically throught a form,  What is the method or function that let assign a field to a entity?



Drupal version: