Skip to content

Simplify creating content from a blueprint programmatically#19528

Merged
lauraneto merged 11 commits intomainfrom
v16/bugfix/19352-creating-content-from-blueprints-programatically
Jun 24, 2025
Merged

Simplify creating content from a blueprint programmatically#19528
lauraneto merged 11 commits intomainfrom
v16/bugfix/19352-creating-content-from-blueprints-programatically

Conversation

@lauraneto
Copy link
Contributor

@lauraneto lauraneto commented Jun 11, 2025

Relates to #19352, but for V16.

This pull request includes the following changes:

  • Adjust the 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.
  • Rename ContentService.CreateContentFromBlueprint() to ContentService.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.
  • Created an integration test to make sure that when creating content from a blueprint, using the different block editors, the keys are replaced with new ones.
    • Moved some of the code for creating simple block data types from ElementSwitchValidatorTests to DataTypeBuilder, so it could be re-used.

…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.
…affoldedAsync` instead of the blueprint itself
@lauraneto lauraneto force-pushed the v16/bugfix/19352-creating-content-from-blueprints-programatically branch from 9d50a08 to 00f2ba8 Compare June 12, 2025 14:45
@lauraneto lauraneto marked this pull request as ready for review June 13, 2025 07:55
Copilot AI review requested due to automatic review settings June 13, 2025 07:55
Copy link
Contributor

Copilot AI left a 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 CreateContentFromBlueprintCreateBlueprintFromContent, 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 with new 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>. Use new Dictionary<string, object>() instead.
_ => [],

Copy link
Contributor

@AndyButland AndyButland left a 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.

…s/ContentBlueprintEditingServiceTests.GetScaffold.cs

Co-authored-by: Andy Butland <abutland73@gmail.com>
@lauraneto lauraneto merged commit 55506ba into main Jun 24, 2025
24 of 25 checks passed
@lauraneto lauraneto deleted the v16/bugfix/19352-creating-content-from-blueprints-programatically branch June 24, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a blueprint with blocks already in them to create content duplicates the ID's of the blocks.

2 participants