GithubHelp home page GithubHelp logo

Comments (15)

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

It uses the Url property to decide on what is output, so if the item is of type Media or Content then it will get the Url from the Content property, if it is any other type it returns the Url property:

https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/develop/src/UmbNav.Core/Extensions/UmbNavItemExtensions.cs#L123

https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/develop/src/UmbNav.Core/Models/UmbNavItem.cs#L67

Hopefully the two above links are helpful

from our.umbraco.umbnav.

mistyn8 avatar mistyn8 commented on September 22, 2024

Is it because the Url property is internal.. so I can't access it to set it on umbNavItem? for a link??

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

Ah yeah probably, I did that to force the use of the Extension when rendering, I don't really want to make that public again, as I can forsee what will happen, especially on multi-lingual sites.

Open to other ideas though

from our.umbraco.umbnav.

mistyn8 avatar mistyn8 commented on September 22, 2024

could we use a deserialiser... I presume there already is one to take

{
            "description": "/department-forms/classic-car-valuation",
            "title": "testing",
            "url": "/department-forms/classic-car-valuation",
            "children": [],
            "icon": "icon-link",
            "itemType": "link"
          }

this back to a umbNavItem?

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

That is done here:
https://github.com/AaronSadlerUK/Our.Umbraco.UmbNav/blob/develop/src/UmbNav.Core/ValueConverters/UmbNavV8ValueConverter.cs#L62

from our.umbraco.umbnav.

mistyn8 avatar mistyn8 commented on September 22, 2024

So this does work.. but feels dirty... Though it is interesting that internal properties can be deserialised to.

var json = "{\"description\": \"/department-forms/classic-car-valuation\", \"title\": \"123testing\", \"url\": \"/department-forms/classic-car-valuation\", \"children\": [], \"icon\": \"icon-link\", \"itemType\": \"link\"}";

var navitem = Newtonsoft.Json.JsonConvert.DeserializeObject<UmbNavItem>(json);
navitem.Level = item.Level;

cchildren.Insert(i + 1, navitem);

Had to manually add the level after deserialisation as that is set to be [ignored] from the json (as you will rightly be calculating it from the nesting).

from our.umbraco.umbnav.

cibis-adrian avatar cibis-adrian commented on September 22, 2024

We also have the same issue. It would be nice to have access to the full functionality of the class.

Because there is an extension to get the Url, perhaps the setter could at least be opened up?

[JsonProperty("url")] public string Url { internal get; set; }

There are many more properties that are internal which don't have a getter/extension method. Perhaps these could just be opened up?

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

For the Url property i do not want to allow it to be used for the rendering.

The .Url() extension is what's to be used to get the link due to the additional parts.

I can make this an internal set if it will solve the problem?

As for the other properties what ones would you need access to?

And can you provide some examples so I can test the change doesn't break other parts of the system.

Thanks!

As always PRs are welcome

from our.umbraco.umbnav.

cibis-adrian avatar cibis-adrian commented on September 22, 2024

Url is the only one we need access to (not sure on what other users may need or how they have things set up).

An internal getter with a public setter should do the trick (you mentioned internal set, it should be public set). That will keep access to it going through the extension method as you intend, but still allow these injected cases to work without resorting to deserialization or reflection.

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

I will have a look at this today

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

@mistyn8 / @cibis-adrian So what I have done in PR #49 is moved all the internal classes into a new class called UmbNavInternalItem this has a property called Url which has an internal getter.

The UmbNavItem still has an internal Url property which is used by the Extension, but cannot be rendered out.

If you think this solves your issue I am happy to merge, however it will be a breaking change for your implementations.

from our.umbraco.umbnav.

cibis-adrian avatar cibis-adrian commented on September 22, 2024

@AaronSadlerUK If the line of code I mentioned was applied directly on the UmbNavItem instead of splitting it into a new class, I believe everything would have just worked without it becoming a breaking change.

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

Yes, but i do not want the Url property available on the rendering class, which it was with that line of code.

This way the extension is still the only Url, and injection can happen

from our.umbraco.umbnav.

cibis-adrian avatar cibis-adrian commented on September 22, 2024

The Url properly won't be available for rendering, it would still be internal exactly like it was before. Try it out and see. I have a local build where I've made the change I mentioned and .Url is not available as a getter so it can't be used when rendering, you have to use the .Url() extension method. But you can still do .Url = "url" for injection cases because the setter is public.

Up to you, if you want it the way you've done and as a breaking change I guess that's fine as long as it works (not sure when I'll have the time to be able to test it).

from our.umbraco.umbnav.

AaronSadlerUK avatar AaronSadlerUK commented on September 22, 2024

I had a try the way you suggested, and the Url property was visible on the class, and I can forsee issues being raised that it doesn't work when people try to use it for rendering.

So I will go with my PR in the next version, the only change required in your code should be the class name from UmbNavItem to UmbNavInternalItem

from our.umbraco.umbnav.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.