DisplayManagement: Fixing that stylesheets that don't exist shouldn't create shapes (#8199)

This commit is contained in:
Márk Bartha
2019-05-15 17:52:00 +02:00
committed by Benedek Farkas
parent b64280174c
commit ecc089a7a6

View File

@@ -92,16 +92,29 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy {
var shape = ((dynamic)displayContext.Value);
var output = displayContext.ViewContext.Writer;
ResourceDefinition resource = shape.Resource;
string url = shape.Url;
var url = GetResourceUrl(shape.Url, hit.fileVirtualPath);
string condition = shape.Condition;
Dictionary<string, string> attributes = shape.TagAttributes;
ResourceManager.WriteResource(output, resource, url ?? hit.fileVirtualPath, condition, attributes);
ResourceManager.WriteResource(output, resource, url, condition, attributes);
return null;
});
}
}
}
private string GetResourceUrl(string shapeUrl, string fileVirtualPath) {
if (string.IsNullOrEmpty(shapeUrl)) return fileVirtualPath;
return GetPathFromRelativeUrl(shapeUrl) == GetPathFromRelativeUrl(fileVirtualPath) ? shapeUrl : fileVirtualPath;
}
private string GetPathFromRelativeUrl(string url) {
var path = url.TrimStart('~');
var indexOfQueryString = path.IndexOf('?');
return indexOfQueryString >= 0 ? path.Substring(0, indexOfQueryString) : path;
}
private bool FeatureIsEnabled(FeatureDescriptor fd) {
return (DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
_shellDescriptor.Features.Any(sf => sf.Name == fd.Id);