Fixed editContent.aspx to let the business logic handle the property validation when trying to publish and show the correct status message result (if it was not publishable). Adds the invalid properties collection to the PublishStatus so those can be shown too.

This commit is contained in:
Shannon
2013-07-24 12:54:10 +10:00
parent 4d39ce1202
commit 7f4abb4893
9 changed files with 102 additions and 58 deletions

View File

@@ -27,6 +27,7 @@ namespace Umbraco.Core.Models
private bool _trashed;
private int _contentTypeId;
private PropertyCollection _properties;
private readonly List<Property> _lastInvalidProperties = new List<Property>();
/// <summary>
/// Protected constructor for ContentBase (Base for Content and Media)
@@ -421,7 +422,17 @@ namespace Umbraco.Core.Models
/// <returns>True if content is valid otherwise false</returns>
public virtual bool IsValid()
{
return Properties.Any(property => !property.IsValid()) == false;
_lastInvalidProperties.Clear();
_lastInvalidProperties.AddRange(Properties.Where(property => property.IsValid() == false));
return _lastInvalidProperties.Any() == false;
}
/// <summary>
/// Returns a collection of the result of the last validation process, this collection contains all invalid properties.
/// </summary>
internal IEnumerable<Property> LastInvalidProperties
{
get { return _lastInvalidProperties; }
}
public abstract void ChangeTrashedState(bool isTrashed, int parentId = -20);

View File

@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Umbraco.Core.Models;
namespace Umbraco.Core.Publishing
@@ -10,6 +11,11 @@ namespace Umbraco.Core.Publishing
public IContent ContentItem { get; private set; }
public PublishStatusType StatusType { get; internal set; }
/// <summary>
/// Gets sets the invalid properties if the status failed due to validation.
/// </summary>
public IEnumerable<Property> InvalidProperties { get; set; }
public PublishStatus(IContent content, PublishStatusType statusType)
{
ContentItem = content;
@@ -24,6 +30,5 @@ namespace Umbraco.Core.Publishing
{
}
}
}

View File

@@ -1552,6 +1552,8 @@ namespace Umbraco.Core.Services
publishStatus.StatusType = CheckAndLogIsPublishable(content);
//Content contains invalid property values and can therefore not be published - fire event?
publishStatus.StatusType = CheckAndLogIsValid(content);
//set the invalid properties (if there are any)
publishStatus.InvalidProperties = ((ContentBase) content).LastInvalidProperties;
//if we're still successful, then publish using the strategy
if (publishStatus.StatusType == PublishStatusType.Success)