Change record status: 
Project: 
Introduced in branch: 
11.3.x
Introduced in version: 
11.3.0
Description: 

The node_add_body_field method was only used in test code by Drupal core.

The function is now deprecated, there is no direct replacement.

If you need to create content types in tests with a body field, use ContentTypeCreationTrait::createContentType which will automatically add a body field.

If you need to add body fields for other entity types, there is also a new BodyFieldCreationTrait to add the same type of field to any bundle.

Otherwise you can create the field config directly:

  $field_storage = FieldStorageConfig::loadByName('node', 'body');
  $field = FieldConfig::loadByName('node', $bundle, 'body');
  if (!$field) {
    $field = FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $bundle,
      'label' => $label,
      'settings' => [
        'display_summary' => TRUE,
        'allowed_formats' => [],
      ],
    ]);
    $field->save();
  }
Impacts: 
Module developers