AaronSadlerUK / Our.Umbraco.UmbNav

Drag and drop menu editor for Umbraco V8, V9 and V10+
MIT License
10 stars 15 forks source link

When ItemType == Link, cannot get Url #76

Closed AussieInSeattle closed 1 year ago

AussieInSeattle commented 1 year ago

Which exact Umbraco version are you using? For example: 8.7.0 - don't just write v8 or v9

8.16.0

Bug summary

Umbraco 8.16.0 UmbNav 1.1.4

Code below fails as .Url is set to internal .Url() also fails - when linking to umbraco content, .Content.Url() works - this is just an issue when the type is Link.

if (subNavItem.ItemType == UmbNav.Core.Enums.UmbNavItemType.Link)
{
  <a href="@subNavItem.Url">@subNavItem.Title</a>
}

Specifics

Seems to be that this line is set to internal? https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/umbraco-v8-v9/src/UmbNav.Core/Models/UmbNavItem.cs#L67

Steps to reproduce

see code above

Expected result / actual result

No response

AaronSadlerUK commented 1 year ago

Yes that's correct, you need to use the extension method

.Url()

AussieInSeattle commented 1 year ago

that fails also (this is for type=link, not type=content) - see screenshot - am I missing a using that would make .Url() work?

image

AaronSadlerUK commented 1 year ago

Hmmm .Url() is in the UmbNav.Core DLL

It's been a long time since I've touched V1, I think link is for external URLs, I'd need to get a V8 site up and running to debug

AussieInSeattle commented 1 year ago

I think link is for external URLs Correct - this is only an issue for external url's - am assuming this is only coming up now as it's rare to have external url's in your top navigation where this package is likely mostly used?

AaronSadlerUK commented 1 year ago

Yeah I think that could be the case, I've done this and got it working in V10+ So I presume it's a bug specific to V8...

I'll do some digging...

Can you give me an example of the backoffice item, so I can be 100% sure I'm debugging it correctly

AussieInSeattle commented 1 year ago

When debugging I can see .Url (string) populated under Non-Public Properties - so I think it's a matter of making .Url public but only when type=link - not sure who you'd do that

AaronSadlerUK commented 1 year ago

That was made internal for a specific reason, it broke things with the multilingual which is why the extension method was brought in... I will debug this and get back to you

AussieInSeattle commented 1 year ago

Example below - cut off the bottom so I didnt have to blur out my content tree image

AussieInSeattle commented 1 year ago

That was made internal for a specific reason, it broke things with the multilingual which is why the extension method was brought in... I will debug this and get back to you

thanks - let me know if you need more info

AaronSadlerUK commented 1 year ago

I've just run V8 and it works for me: image image

These are the two usings:

@using UmbNav.Core.Extensions
@using UmbNav.Core.Models

Are you sure the Url() you are using in your code is the UmbNav one? Your error seems to say PublishedContentExtensions.Url() whereas the UmbNav one is UmbNavItemExtensions.Url()

AaronSadlerUK commented 1 year ago

Just to add the UmbNav extension does a null check here: https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/ac2e3a9a59e8c2c5c8a8274443dad912ad9c0b8f/src/UmbNav.Core/Extensions/UmbNavItemExtensions.cs#L125

and returns .Url if it is null here: https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/ac2e3a9a59e8c2c5c8a8274443dad912ad9c0b8f/src/UmbNav.Core/Extensions/UmbNavItemExtensions.cs#L151

AussieInSeattle commented 1 year ago

good catch - missing using statement - adding this to view fixed it: @using UmbNav.Core.Extensions Will buy you a beer at CG for your troubles :-)

AaronSadlerUK commented 1 year ago

Glad you got it working!