How do I unlock a field? In Drupal 7 it is possible to use:

$field_name = 'field_name';
$field = field_read_field($field_name);
$field['locked'] = 0; // 0: unlock; 1: lock.
field_update_field($field);


How to do this in Drupal 8?
You need to load the related field storage config entity and change the locked status:

\Drupal::entityTypeManager()
  -&gt;getStorage('field_storage_config')
  -&gt;load('node.field_foo')
  -&gt;setLocked(FALSE)
  -&gt;save();


This is just an example - you should inject the entity type manager instead of calling the global version if contexts allows.