0
votes

I have a custom module that replaces the default RolesBasedAuthorizationService with almost identical code, except that, when my custom module is enabled, it will pull roles from a service instead of from the user. Enabling the service involves filling out information in Settings and checking a box.

Since the roles are replaced when using my custom module (and the functionality is enabled), I want to hide the roles on the Edit User page. Following Understanding placement info, I can successfully hide the Roles list using the following in my custom module's placement.info:

<Match ContentType="User">
  <Place Parts_Roles_UserRoles_Edit="-" />
</Match>

However, that will hide the list whenever my module's feature is enabled. But the feature being enabled isn't all that has to happen for the feature to do its magic - the checkbox also has to be checked (which provides the ability to enter the required settings before turning on the service-based authorization). So, continuing with that same piece of documentation, I can create a wrapper and apply it like so:

<Match ContentType="User">
  <Place Parts_Roles_UserRoles_Edit="Content:10;Wrapper=Wrapper_HideIfCondition" />
</Match>

This should allow me to wrap the roles list like so:

<div style="display: block">
    @Model.Html
</div>

I'm currently using display: block to make sure the wrapper is being called; however, the roles list disappears - it appears that Orchard isn't finding the wrapper. The cshtml file exists at MyCurrentTheme\Views\Wrapper.HideIfCondition.cshtml - I was hoping to get it into the Module, but I'll wait on that until I get it working in the default way (in the theme).

So my current question is thus: What am I missing in order to get the wrapper to be found and used?

1
Are you talking about the edit user page in the admin? - Hazza
@Hazza: That's correct. I'm trying to wrap the roles checkboxes on that page. - zimdanen
Well, the reason it won't work how you are doing it currently is that the theme isn't being applied in the admin. The Admin Theme is. So you could chuck your code in the Admin Theme, then it would work. Preferably create your own admin theme if that is the route you are going to go down. - Hazza

1 Answers

1
votes

Well, the reason it won't work how you are doing it currently is that your theme isn't being applied in the admin. The Admin Theme is. So you could chuck your code in the Admin Theme, then it would work. Preferably create your own admin theme if that is the route you are going to go down.

If you want to put it in a module, you need to make sure your module depends upon Orchard.Roles else Orchard.Roles placement will take priority. So in your module.txt you will need this line:

Dependencies: Orchard.Roles

Placement file:

 <Match ContentType="User">
  <Place Parts_Roles_UserRoles_Edit="Content:10;Wrapper=Wrappers_HideIfCondition" />
 </Match>

Then you wrapper will be in your views folder and called Wrappers.HideIfCondition.cshtml with something like:

@using Orchard.ContentManagement;

@{
    var condition = true;
}

@if(condition)
{
    @Display(Model.Metadata.ChildContent)
}

<p>I am a wrapper</p>

Hope this helps