-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Simplify creating content from a blueprint programmatically #19528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Simplify creating content from a blueprint programmatically #19528
Conversation
…ntFromContent` In reality, this method is used by the core to create a blueprint from content, and not the other way around, which doesn't need new ids. This was causing confusion, so the old name has been marked as deprecated in favor of the new name. If developers want to create content from blueprints they should use `IContentBlueprintEditingService.GetScaffoldedAsync()` instead, which is what is used by the management api.
…en creating content from a blueprint
…affoldedAsync` instead of the blueprint itself
…entFromBlueprint`
…rints-programatically
9d50a08
to
00f2ba8
Compare
…rints-programatically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR simplifies programmatic blueprint-based content creation by returning clone scaffolds, renaming key methods for clarity, and expanding integration tests for block editors.
GetScaffoldedAsync
now returns a cloned blueprint with reset identity.- Renamed
CreateContentFromBlueprint
→CreateBlueprintFromContent
, marking the old method obsolete. - Added integration tests covering block editors and extracted reusable block data type builder logic.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentBlueprintEditingServiceTests.cs | Added JSON serializer dependency and adjusted array initializers. |
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentBlueprintEditingServiceTests.GetScaffold.cs | Enhanced scaffold tests for block editors; introduced new block key assertions. |
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs | Updated a test to use GetScaffoldedAsync and switched to async. |
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ElementSwitchValidatorTests.cs | Refactored data type setup to use new CreateSimpleElementDataType . |
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs | Renamed test and updated calls to use CreateBlueprintFromContent . |
tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTestWithContent.cs | Added IDataTypeService to test base class. |
tests/Umbraco.Tests.Common/Builders/DataTypeBuilder.cs | Introduced CreateSimpleElementDataType helper and moved block configuration logic. |
src/Umbraco.Core/Services/IContentService.cs | Renamed interface methods, added default implementation, marked old method obsolete. |
src/Umbraco.Core/Services/ContentService.cs | Renamed and refactored content/blueprint creation methods, updated null checks. |
src/Umbraco.Core/Services/ContentBlueprintEditingService.cs | Implemented deep-clone scaffold logic and updated notification payload. |
Comments suppressed due to low confidence (2)
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentBlueprintEditingServiceTests.GetScaffold.cs:88
- Initializing a List with
[]
causes a type mismatch. Replace withnew List<Guid>()
or use a collection expression that returns List.
List<Guid> newKeys = [];
tests/Umbraco.Tests.Common/Builders/DataTypeBuilder.cs:172
- Default switch arm returns
[]
which is an empty array, not a Dictionary<string, object>. Usenew Dictionary<string, object>()
instead.
_ => [],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic, excellent work on the integration tests. I could only find one nit-pick that I've suggested, other than that all good to merge in and close off the related issue.
|
||
foreach (var newKey in newKeys) | ||
{ | ||
Assert.IsTrue(!blueprint.BlockKeys.Contains(newKey), "The blocks in a content item generated from a template should have new keys."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.IsTrue(!blueprint.BlockKeys.Contains(newKey), "The blocks in a content item generated from a template should have new keys."); | |
Assert.IsFalse(blueprint.BlockKeys.Contains(newKey), "The blocks in a content item generated from a template should have new keys."); |
Just a bit more readable this way around.
Relates to #19352, but for V16.
This pull request includes the following changes:
ContentBlueprintEditingService.GetScaffoldedAsync()
to return a copy of the blueprint, instead of the blueprint itself, with the identity reset. This will allow developers to simply call this method and save the content as a new item without much effort.ContentService.CreateContentFromBlueprint()
toContentService.CreateBlueprintFromContent()
, as this better explains its purpose (and how it is used in the core). Marked the old method as obsolete, with a message and xml docs mentioning the other methods.ElementSwitchValidatorTests
toDataTypeBuilder
, so it could be re-used.