Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Adding new boolean that defaults to true

Vote:
0

I have a lot of existing categories.

Now I want to add a new "VisibleInMenu" bool property to categories, and I want it to be checked by default i all the exisiting categories.

I have tried the SetDefaultValues approach, which did not work:

public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
VisibleInMenu = true;
}

I've tried overwrititng the get/set of the property, and that did not work:

[Display(Name = "Display in navigation", GroupName = SystemTabNames.PageHeader, Order = 1000)]
public virtual bool VisibleInMenu
{
get
{
return (bool)(this["VisibleInMenu"] ?? true);
}
set
{
this["VisibleInMenu"] = value;
}
}

Is this even possible without looping through all the categories and setting the value?

#180784
Jul 26, 2017 11:30
Vote:
0

Unfortunately I don't think there is a way other than a migration. For these boolean cases (where I can't check for null somewhere in my code and use a default there) I sometimes revert the logic, if I find it semantic enough. But perhaps DontShowInMenu is not the best thing after all...

#180786
Jul 26, 2017 12:37
Vote:
0

I would prefer if it could mimic the same semantics as the built in page, but I think I will have to go with a "HideInMenu" property instead.

#180787
Jul 26, 2017 12:39
Vote:
1

Just make sure you use the SetDefaultValues to get the desired value for future creations of the content :)

#180788
Jul 26, 2017 12:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.