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

Empty value when property is shared between cultures #145

Closed
mrtrandinhvn opened this issue May 10, 2023 · 3 comments
Closed

Empty value when property is shared between cultures #145

mrtrandinhvn opened this issue May 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mrtrandinhvn
Copy link

Background

I have a very simple demo umbraco site with these packages installed:

  • <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
  • <PackageReference Include="uSync" Version="11.1.0" />
  • <PackageReference Include="Nikcio.UHeadless" Version="3.3.0" />
  • <PackageReference Include="Umbraco.Cms" Version="11.3.1" />

Steps to reproduce:

  • Create a site with two languages.
  • Create a Document type with "Allow vary by culture" ON.
  • Create a textbox property with "Allow vary by culture" OFF.
  • Go query for that page with one culture:
{
  contentById(id: 1061, culture: "en-us") {
    id
    properties {
      alias
      editorAlias
      value {
        ... on CustomPropertyValue {
          value # Value of that property will be ""
        }
      }
    }
  }
}

Solution

I suspect that the root cause is because you always add Culture when querying for property value. When the correct way to do that (in Umbraco 11) is adding a simple check like this.

public class CustomPropertyValue : BasicPropertyValue
    {
        [GraphQLType(typeof(AnyType))]
        public override object? Value { get; set; }

        public CustomPropertyValue(CreatePropertyValue createPropertyValue) : base(createPropertyValue)
        {
            var property = createPropertyValue.Property;
            Value = property.GetValue(property.PropertyType.Variations == ContentVariation.Culture
                ? createPropertyValue.Culture : string.Empty);
        }
    }

As you can see there will be issues with when "Allow segmentation" involves in, but I'm not experienced enough with Umbraco to think about that right now.

Few words

This project is a game changer for headless cms umbraco. I would love to create a PR but I'm not sure which branch should I fork and create a PR to.
Thank you for your hard work.

@nikcio
Copy link
Owner

nikcio commented May 11, 2023

Thank you for the issue report. Feel free to make a PR for the v3/contrib branch.😉

@nikcio nikcio added the bug Something isn't working label May 16, 2023
nikcio added a commit that referenced this issue May 16, 2023
BREAKING CHANGE:

Introduces `IVariationContextAccessor` to the contructor on `BasicContent`

Related to #145
@nikcio
Copy link
Owner

nikcio commented May 20, 2023

There's a few things that needed to be changed for the culture to work properly with the property values. #147 addresses this but includes multiple breaking changes that need to go with it to give a nice developer experience. Therefore this fix will first come in V4 which is still in the works.

@nikcio
Copy link
Owner

nikcio commented Jun 6, 2023

I'm closing this issue as the fix will be available in v4 and a preview release has now been released. 😄

@nikcio nikcio closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants