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

Accessing settings in a Block custom view always returns the first setting value #17989

Open
johnpscott opened this issue Jan 15, 2025 · 2 comments
Labels

Comments

@johnpscott
Copy link

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

15.1.1

Bug summary

When a BlockGrid block element has a settings model with more than one property any attempt to use the values in a Block Custom View an the back office always returns the first declared property in the settings model.

Specifics

So for example if the settings model has the following property aliases: a, b, c, d, e with values Hay, Bee, See, Dee, He
Code to retrieve properties b to e will always retrieve the value of property a, i.e. Hay

return html<p>${this.settings?.e}</p>

returns

Hay

Steps to reproduce

Add a new block to a BlockGrid data type based on an existing Content model and an existing settings model.
The settings model must have two or more properties (e.g. ForegroundColor and BackgroundColor)

In the custom Typescript view for the grid item access the settings values as so:

    @property({ attribute: false })
    settings?: UmbBlockDataType;

    override render() {
    ...
        var fg= this.settings?.foregroundColor;
        var bg= this.settings?.backgroundColor;
// add more properties if required
    ....

Expected result / actual result

When using the two variables they both return the value of the first declared property in the settings model.

This has been reproduced with up to 5 properties - the first declared property is returned despite being accessed by the properties alias.

This has also be noted in the Our Umbraco forum entry: https://our.umbraco.com/forum/using-umbraco-and-getting-started/115164-umbraco-15-custom-block-grid-displaying-data-type-values-from-a-settings-element-in-cms

Copy link

Hi there @johnpscott!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@johnpscott
Copy link
Author

This issue is still present in the 5.1.2 Contrib branch. I have pinpointed the issue to the following code for 'settingsValues' in 'block-entry-context.ts' at line 234.

					return properties.reduce((acc, property) => {
						acc[property.alias] = propertyValues.find((x) =>
							this.#createPropertyVariantId(property, variantId).compare(x),
						)?.value;
						return acc;
					}, {} as UmbBlockDataType);

By replacing this code with the corresponding code pattern for the 'contentValues' method the problem is resolved. I.e.

					return properties.reduce((acc, property) => {
						const propertyVariantId = this.#createPropertyVariantId(property, variantId);
						acc[property.alias] = propertyValues.find(
							(x) => x.alias === property.alias && propertyVariantId.compare(x),
						)?.value;
						return acc;
					}, {} as UmbBlockDataType);

I am not very familiar with the Umbraco codebase, or the process for proposing code changes, so I haven't been able perform rigorous testing. I hope someone with more experience will pick this up, test and fix the error.

It is a major issue for anyone who wants to make use of the custom edit views in block grid, and it is impeding my attempt to upgrade my Umbraco 11/12 sites to the latest version.

regards

John

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant