Skip to content
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

DX: Add BlockValue constructors to force correct property editor alias and layout item type #16266

Merged
merged 5 commits into from
May 14, 2024

Conversation

ronaldbarendse
Copy link
Contributor

PR #16184 fixed the BlockValue implementation when serializing/deserializing, but creating a new value still required you to use the correct property editor alias and layout item type. For example, it was easy to get the following wrong:

var blockListValue = new BlockListValue()
{
    Layout =
    {
        // This won't store the layout, because it's not the correct one for BlockListValue
        [Constants.PropertyEditors.Aliases.BlockGrid] =
        [
            // Even if the type got updated to BlockGridValue, this layout item shouldn't be allowed
            new BlockListLayoutItem()
        ]
    }
};

Although the CMS codebase only manually creates these values in tests, users might want to programmatically create them. One use case is the Deploy artifact migrators, e.g. if you want to migrate Nested Content to Block List.

With this PR applied, you can use the new constructor overloads to specify the layout, which automatically uses the correct property editor alias (from the abstract property) and forces you to use the correct layout item type:

var blockListValue = new BlockListValue(
[
    new BlockListLayoutItem()
]);

@ronaldbarendse ronaldbarendse requested a review from kjac May 10, 2024 14:11
@kjac
Copy link
Contributor

kjac commented May 14, 2024

Hi @ronaldbarendse --- this is good stuff!

I have taken the liberty to amend the PR a little with a few more pages from your book:

  1. The GetLayouts overload on BlockValue that takes a propertyEditorAlias does not make any sense, because it is enforcing TLayout, so I have removed it (commit)
  2. I have added an extra constructor on BlockItemData to simplify explicit/programmatic usages of that, e.g. in tests (commit).

Does it make sense to you?

@ronaldbarendse
Copy link
Contributor Author

Does it make sense to you?

Yes, both changes make perfect sense, thanks! Feel free to merge when all tests have passed 🥳

Copy link
Contributor

@kjac kjac left a comment

Choose a reason for hiding this comment

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

👍 💯

@kjac kjac merged commit cbf9781 into release/14.0 May 14, 2024
13 checks passed
@kjac kjac deleted the v14/feature/blockvalue-improvements branch May 14, 2024 11:34
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