From 608a65147fbfacbb6f4235a45fa6e4f36306c84f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 18 Mar 2022 08:02:44 +0100 Subject: [PATCH] Fixes --- .../Services/Implement/MacroService.cs | 7 ++++--- .../Templates/HtmlMacroParameterParser.cs | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Services/Implement/MacroService.cs b/src/Umbraco.Infrastructure/Services/Implement/MacroService.cs index 1175c08971..e7770e018f 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/MacroService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/MacroService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Services.Implement { if (_macroRepository is not IMacroWithAliasRepository macroWithAliasRepository) { - return GetAll().First(); + return GetAll().FirstOrDefault(x=>x.Alias == alias); } using (var scope = ScopeProvider.CreateScope(autoComplete: true)) @@ -68,7 +68,8 @@ namespace Umbraco.Cms.Core.Services.Implement { if (_macroRepository is not IMacroWithAliasRepository macroWithAliasRepository) { - return GetAll(); + var hashset = new HashSet(aliases); + return GetAll().Where(x=> hashset.Contains(x.Alias)); } using (var scope = ScopeProvider.CreateScope(autoComplete: true)) diff --git a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs b/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs index 2e1f86fc1b..2b4786bd0a 100644 --- a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs +++ b/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs @@ -88,6 +88,10 @@ namespace Umbraco.Cms.Infrastructure.Templates foreach (var macro in macros) { var macroConfig = macroConfigs.FirstOrDefault(f => f.Alias == macro.Item1); + if (macroConfig is null) + { + continue; + } foundMacroUmbracoEntityReferences.Add(new UmbracoEntityReference(Udi.Create(Constants.UdiEntityType.Macro, macroConfig.Key))); // Only do this if the macros actually have parameters if (macroConfig.Properties != null && macroConfig.Properties.Keys.Any(f => f != "macroAlias"))