'type' =>
$field_type,
]);
$storage->
save();
FieldConfig::
create([ 'field_storage' =>
$storage,
'bundle' =>
$media_type_id,
])->
save();
// Make the field widget visible in the form display.
$component = \Drupal::
service('plugin.manager.field.widget'
) ->
prepareConfiguration($field_type,
[]);
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::
service('entity_display.repository'
);
$entity_form_display =
$display_repository->
getFormDisplay('media',
$media_type_id, 'default'
);
$entity_form_display->
setComponent($field_name,
$component) ->
save();
// Use the default formatter and settings.
$component = \Drupal::
service('plugin.manager.field.formatter'
) ->
prepareConfiguration($field_type,
[]);