Kentico 8: How to introduce a custom Edit Tab, visible only when a document based on a specific doc

Keith Durrant asked on June 11, 2014 17:01

I have introduced a new custom Edit Tab by navigating to Modules -> Custom -> User Interface and adding a new element in the tree at CMS -> Administration -> Content management -> Pages -> Edit

It works as expected.

I now want to restrict it's visibility, visible only when the document selected in the content tree is based on a particular document type. The element I created in the tree has an Element restrictions section containing a Visibility condition field where I'm able to write a macro condition. All the expressions I have tried failed. I have checked and rechecked the class name of the document type to make sure I'm evaluating to the correct value.

Does anybody know the correct expression I should be using in this scenario?

Thanks.

Recent Answers


Zdeněk Cetkovský answered on July 7, 2014 22:51

Hi,

Have you found any solution yet? What kind of expressions have you tried? Context macros? In the UI, you will most likely need to use UIContext.EditedObject, have you tried that?

Thank you in advance for information.

0 votesVote for this answer Mark as a Correct answer

Keith Durrant answered on August 6, 2014 21:58

Hello Zdenek,

Sorry for the late reply. I'm just returning to this issue now in development.

I've tried the following expressions:

  • (CurrentDocument.ClassName == "namespace.codename")
  • ((TreeNode)UIContext.EditedObject).ClassName == "namespace.codename"

Neither work. I assume both evaluate to "false" because the tab isn't available at all when the visibility condition is in place.

0 votesVote for this answer Mark as a Correct answer

Joe Krill answered on November 19, 2014 19:35

I see this is a few months old, but I wanted to jump in since I've spent the better part of a day trying to do the same exact thing.

Ultimately, here is what I ended up using as my Visibility condition (found under Element restrictions on the General tab):

System.GetObject("cms.node",Convert.ToInt(QueryString.nodeid, 0)).NodeClass == "Intranet department"

In my case, I only wanted this tab visible to pages that were "IntranetPortal.Department" pages. So replace Intranet department with the display name (not the code name!) of the class you're looking for.

So this works. But it doesn't particularly feel right to me. I was at least hoping to use the class name (code name), and not the display name. But I couldn't figure out any way to get that.

Some additional notes/info on how I figured this out:

It seems that UIContext.EditedObject and UIContext.EditedObjectParent are null in this context. And if you follow the tree up and look in the Properties tab of each of the parent nodes ("Edit", "Pages") you can see that Object type and Parent Object Type are not set. Which is (I think!) where those UIContext properties come from. CurrentDocument is null as well.

UIContext.Data seems to hold some relevant information, but I couldn't figure out exactly what, and exactly how to access some of it. Which sounds rather strange so let me explain: I was using the Object listing page template for my UI element. In the Properties tab there is a Header text field that allows macros. So I was really just blindly testing the values of various objects using this field, and refreshing that tab in another browser window to see what it produced. This is how I know CurrentDocument, UIContext.EditedObject, and UIContext.EditedObject parent are all null. If I entered {% CurrentDocument ?? "(null)"%} in here, the header text would produce "(null)".

So when I entered {%UIContext.Data%} as a value, it spit out a string that included the underlying QueryString values, but also some other properties that I couldn't figure out how to access. The module name was in there. As was the object type (I think?). I don't really. I eventually gave up and went with the method above, because I didn't want to waste any more time poking around here.

In the end, I'm convinced there must be a much easier way to do this. But I don't know what it is. So if anyone has some insight here, I'd love to hear it.

0 votesVote for this answer Mark as a Correct answer

Joe Krill answered on December 31, 2014 16:03

Quick update: I figured out how to access the node class name instead of only the display name:

{% System.GetObject("cms.node",Convert.ToInt(QueryString.nodeid, 0)).NodeClass.ClassName == "intranetportal.department" %}

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.