Quick question.. We use the
# contributing
r
Quick question.. We use the IPublishedContent extensions a lot and it seems like AncestorOfSelf(contentTypeAlias) has been changed in behaviour. For example we have this node structure: - Festival node (documenttype: "festival") - Text node - News overview node - News article Then in our template we want to know if the current page is a childnode of the Festival node, so we simply did this: bool isFestivalChildNode = Model.AncestorOrSelf("festival") != null; This always worked fine, but after upgrading our site to Umbraco 13, AncestorOrSelf returns the node itself, and never null. So in our example when being on News article page, isFestivalChildNode returns true as well, because Model.AncestorOrSelf("festival") returns News article node. This is the static function in Umbraco core: public static IPublishedContent AncestorOrSelf(this IPublishedContent content, string contentTypeAlias) => content .EnumerateAncestors(true).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)) ?? content; As you can see it simply returns content (??) when Ancestor is not found. Long question short: why is this bevahiour chosen for this extension method? This doesn't make any sense right? Or am I making a mistake over here? Is there any quick fix I could use maybe?
r
ah thanks, didn't find that one
"We concluded that we're not changing the behaviour of the AncestorOrSelf method, mostly because this would be very subtly breaking, and we'd like to avoid that." Hmm think it's breaking when not changed, but who am I 😛
s
Tell that to the thousands of people who's site we'd break by changing the behavior 😂 😅
j
The most egregious thing about the extension method is the discrepancy in behaviour between
Model.AncestorOrSelf("festival")
and
Model.AncestorOrSelf<Festival>()
If you swap the magic string with the type, you will get the expected behaviour. It'd be nice if someone could update the XML comments to match the new behaviour.