published and unpublished values in notification handlers
Hi All,
Just wondering if I should raise a bug for this or is there a reason for this behaviour.
This happens on all properties, but to illustrate the issue, I have a property called "metaTitle" on one of my document types. When i edit the value and click "Save and Publish", the "saving" notification handler allows me to get the unpublished and published version of the property value. This is what I would expect. But the "publishing" handler does not give me the same values. it gives me the newly edited value for both. See the image below which explains the issue:
Both the ContentSavingNotification and ContentPublishingNotification inherit from a generic class and implement it with the IContent type. IContent inherits from IContentBase that has the method GetValue<T>:
public TValue GetValue<TValue>(string propertyTypeAlias, string culture = null, string segment = null, bool published = false)
{
if (!Properties.TryGetValue(propertyTypeAlias, out var property))
return default;
var convertAttempt = property.GetValue(culture, segment, published).TryConvertTo<TValue>();
return convertAttempt.Success ? convertAttempt.Result : default;
}
This method then uses the Property implementation of IProperty GetValue which in turn uses a private method GetPropertyValue:
public object GetValue(string culture = null, string segment = null, bool published = false)
{
// ensure null or whitespace are nulls
culture = culture.NullOrWhiteSpaceAsNull();
segment = segment.NullOrWhiteSpaceAsNull();
if (!PropertyType.SupportsVariation(culture, segment)) return null;
if (culture == null && segment == null) return GetPropertyValue(_pvalue, published);
if (_vvalues == null) return null;
return _vvalues.TryGetValue(new CompositeNStringNStringKey(culture, segment), out var pvalue)
? GetPropertyValue(pvalue, published)
: null;
}
private object GetPropertyValue(IPropertyValue pvalue, bool published)
{
if (pvalue == null) return null;
return PropertyType.SupportsPublishing
? (published ? pvalue.PublishedValue : pvalue.EditedValue)
: pvalue.EditedValue;
}
This last method is the point where the variable published is finally used and determains what value is returned.
So either SupportsPublishing is false and therefore returns the EditedValue or the value is changed between the saving and publishing notification. I could not figure out what was the case.
Also I was able to replicate this issue in V10. And found another issue where unpublished content still returns a value when you call the method GetValue<> with the parameter published set to true.
Since this still happens in V10 it's defenitly worth making a GitHub issue about this item.
published and unpublished values in notification handlers
Hi All,
Just wondering if I should raise a bug for this or is there a reason for this behaviour.
This happens on all properties, but to illustrate the issue, I have a property called "metaTitle" on one of my document types. When i edit the value and click "Save and Publish", the "saving" notification handler allows me to get the unpublished and published version of the property value. This is what I would expect. But the "publishing" handler does not give me the same values. it gives me the newly edited value for both. See the image below which explains the issue:
Both the
ContentSavingNotification
andContentPublishingNotification
inherit from a generic class and implement it with theIContent
type.IContent
inherits fromIContentBase
that has the methodGetValue<T>
:This method then uses the Property implementation of IProperty
GetValue
which in turn uses a private methodGetPropertyValue
:This last method is the point where the variable
published
is finally used and determains what value is returned. So eitherSupportsPublishing
is false and therefore returns theEditedValue
or the value is changed between the saving and publishing notification. I could not figure out what was the case.Also I was able to replicate this issue in V10. And found another issue where unpublished content still returns a value when you call the method
GetValue<>
with the parameterpublished
set totrue
.Since this still happens in V10 it's defenitly worth making a GitHub issue about this item.
is working on a reply...