Adds a field to a given paragraph type.
string $paragraph_type_name: Paragraph type name to be used.
string $field_name: Paragraphs field name to be used.
string $field_type: Type of the field.
array $field_edit: Edit settings for the field.
protected function addParagraphsField($paragraph_type_name, $field_name, $field_type, $field_edit = []) {
// Add a paragraphs field.
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'paragraph',
'type' => $field_type,
'cardinality' => '-1',
'settings' => $field_edit,
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $paragraph_type_name,
'settings' => [
'handler' => 'default:paragraph',
'handler_settings' => [
'target_bundles' => NULL,
],
],
]);
$field
->save();
}