Skip to content

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

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 Copilot AI review requested due to automatic review settings June 13, 2025 07:55
Copy link
Contributor

@Copilot 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.


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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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.

2 participants