-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix media tracking of items added via macro parameters in RTE and Grid #12139
Merged
Zeegaan
merged 15 commits into
v9/dev
from
v9/bugfix/track-media-items-picked-as-macro-params
Mar 21, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
17266da
New service and repo to get macros by alias
elit0451 2aa79c7
Adding repository caching of macro definition by alias
elit0451 cbb19b1
Implementations of the new interfaces
elit0451 c22b9db
Adding a new parser to get the media references in a macro
elit0451 92480b8
Changes in the editors so we can track the items
elit0451 cf9f4f3
Adds/Fixes xdoc comments
elit0451 22b7771
Changing the way we implement the new Macro service and repository
elit0451 5d08caa
Cleanup
elit0451 5bebf98
Test + fix
elit0451 c08921d
Merge remote-tracking branch 'origin/v9/dev' into v9/bugfix/track-med…
elit0451 608a651
Fixes
bergmania 0f3aa32
Fix caching & contentPicker in parameter
8e78de4
Abstract ParameterValueEditors
93432a2
Apply suggestions from code review
Zeegaan a02ef3c
Try to make test non-flaky
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Umbraco.Core/Persistence/Repositories/IMacroWithAliasRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Umbraco.Cms.Core.Models; | ||
|
||
namespace Umbraco.Cms.Core.Persistence.Repositories | ||
{ | ||
[Obsolete("This interface will be merged with IMacroRepository in Umbraco 11")] | ||
public interface IMacroWithAliasRepository : IMacroRepository | ||
{ | ||
IMacro GetByAlias(string alias); | ||
|
||
IEnumerable<IMacro> GetAllByAlias(string[] aliases); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePickerParamateterValueEditorBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Umbraco.Cms.Core.IO; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.Editors; | ||
using Umbraco.Cms.Core.Serialization; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Strings; | ||
|
||
namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors | ||
{ | ||
internal abstract class MultiplePickerParamateterValueEditorBase : DataValueEditor, IDataValueReference | ||
{ | ||
private readonly IEntityService _entityService; | ||
|
||
public MultiplePickerParamateterValueEditorBase( | ||
ILocalizedTextService localizedTextService, | ||
IShortStringHelper shortStringHelper, | ||
IJsonSerializer jsonSerializer, | ||
IIOHelper ioHelper, | ||
DataEditorAttribute attribute, | ||
IEntityService entityService) | ||
: base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) | ||
{ | ||
_entityService = entityService; | ||
} | ||
|
||
public abstract string UdiEntityType { get; } | ||
public abstract UmbracoObjectTypes UmbracoObjectType { get; } | ||
public IEnumerable<UmbracoEntityReference> GetReferences(object value) | ||
{ | ||
var asString = value is string str ? str : value?.ToString(); | ||
|
||
if (string.IsNullOrEmpty(asString)) | ||
{ | ||
yield break; | ||
} | ||
|
||
foreach (var udiStr in asString.Split(',')) | ||
{ | ||
if (UdiParser.TryParse(udiStr, out Udi udi)) | ||
{ | ||
yield return new UmbracoEntityReference(udi); | ||
} | ||
|
||
// this is needed to support the legacy case when the multiple media picker parameter editor stores ints not udis | ||
if (int.TryParse(udiStr, out var id)) | ||
{ | ||
Attempt<Guid> guidAttempt = _entityService.GetKey(id, UmbracoObjectType); | ||
Guid guid = guidAttempt.Success ? guidAttempt.Result : Guid.Empty; | ||
|
||
if (guid != Guid.Empty) | ||
{ | ||
yield return new UmbracoEntityReference(new GuidUdi(Constants.UdiEntityType.Media, guid)); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Umbraco.Cms.Core.Models; | ||
|
||
namespace Umbraco.Cms.Core.Services | ||
{ | ||
[Obsolete("This interface will be merged with IMacroService in Umbraco 11")] | ||
public interface IMacroWithAliasService : IMacroService | ||
{ | ||
/// <summary> | ||
/// Gets a list of available <see cref="IMacro"/> objects by alias. | ||
/// </summary> | ||
/// <param name="aliases">Optional array of aliases to limit the results</param> | ||
/// <returns>An enumerable list of <see cref="IMacro"/> objects</returns> | ||
IEnumerable<IMacro> GetAll(params string[] aliases); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zeegaan shouldn't it just use
Length
here since the aliases isstring[]
.for example:
As far I know
Any()
check first item if collection, but withArray
,List
,ICollection
etc,Length
orCount
property already know the size of the array/collection.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @bjarnef, thanks for your comment, i had to check how this works 👀 When it is an array, Any() will also use the
Count
property like this:And because of that, i think its more readable if we use
Any()
instead ofLength