Using a wrapper to conditionally hide roles on Edit User page - orchardcms

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?

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

Related

Liferay 7.4: How to create a configurable web content article footer?

I need to create a footer in a Liferay-project, that can be modified from the instance. I've been trying various things in my footer-code and instance, but haven't figured out how to do it.
Any content inside the footer can't be touched and in page edit mode, Liferay says "This area is defined by the theme. You can change the theme settings by clicking more in the Page Design Options panel on the sidebar". I didn't get any help from Page Design Options either. Is there a way to do this?
I found the answer after hours of work and searching and want to share it with everyone here. The working solution was found here, in one of the comments.
You need to write some code (I use Freemarker/ftl) and then configure the site pages a bit, but here's how it works:
Put a new setting inside liferay-look-and-feel.xml:
<settings>
<setting key="footer-article-id" value="" configurable="true" type="text"/>
</settings>
This will create a new configurable option in page options, allowing you to input the ID of the web content.
NOTE: <theme> might get underlined red "The content of element type "theme" must match". This still prints everything correctly, but the tags are given in a wrong order. Inside my <theme>, I have <template-extension>, <settings> and <portlet-decorator> in that order, which removes the error.
Assign a variable in init_custom.ftl (cleans up the footer-code):
<#assign footer_article_id = getterUtil.getString(themeDisplay.getThemeSetting("footer-article-id"))/>
And then add this to the footer-code, to create the spot, where the content is visible:
<#liferay_journal["journal-article"]
articleId=footer_article_id
groupId=page_group.groupId
/>
After this, everything should be ready code-wise.
Create a Web Content for your footer. In the creation screen, there's an ID on the panel on the right. Publish your content and grab the ID.
Finally, go to Site Builder --> Pages and click on configuration from the top bar (behind three dots). You should see the input field like in the first picture: That's where you add the ID.
Save the settings and your web content should now be in the footer.
Hope this helps!

Orchard CMS - How to Get Current DisplayType

I have a custom ContentPart as well as an editor view under Views/EditorTemplates/Parts/ folder. I am trying to figure out the appropriate DisplayType value to use in my placement.info file to get this view to kick in. I see it show up if I use something like this:
<Match ContentType="MyType">
<Place Parts_MyPart_Edit="Content"/>
</Match>
But I'd like to be able to target it a little more explicitly like:
<Match ContentType="MyType">
<Match DisplayType="????">-->
<Place Parts_MyPart_Edit="Content"/>
</Match>
</Match>
I have tried "Detail", "Summary", and "SummaryAdmin" unsuccessfully.
So 2 questions:
Is there a standard list of "DisplayType" values documented somewhere?
Is there a way to discover what the "DisplayType" is at runtime via a breakpoint or otherwise so that I can further restrict it in the placement.info?
Edit
Thinking about this a bit more, is 'DisplayType' even involved when Editor templates are used? I just realized that Parts_MyPart_Edit may be restrictive enough since it is already targetting _Edit. Is this right, or is there also an option to match on 'DisplayType' that can be used for editor templates?
1: Don't know exactly where the correct documentation is on this topic, but this is the correct syntax:
<Match DisplayType="Summary"> Detail and SummaryAdmin are also valid display types.
Besides that, you can also define your own display type:
var shape = _contentManager.BuildDisplay(item, "CustomDisplayType");
Then your shapes/views must be named as YourShape.CustomDisplayType.cshtml.
Then you can use your displaytype in placement.info:
<Match DisplayType="CustomDisplayType">
<Place Parts_YourPart="Content:1" />
</Match>
2: Use the 'shape tracer' module. When enabled you can find in the front-end which display type is used.
You probably made a mistake with either the <Place Parts_ section or your part driver is not correctly implemented. Also check if your shape's name is correct.
Posting this as an answer, since I don't have a high enough reputation to add comment yet :)
If you are interested in using Shape Tracer on admin pages, open up the ShapeTracingFactory.cs file in Orchard.DesignerTools module, and comment out the following line in the IsActivable method:
if (AdminFilter.IsApplied(new RequestContext(_workContext.HttpContext, new RouteData())))
return false;
I have found this extremely useful for figuring out exactly what is happening during Content Authoring tasks

Orchard Placement file not hiding the Title Part

In Orchard I have a placement.info file that should hide the Title part when I view an Author:
<Match ContentType="Author">
<Place Parts_Title="-" />
<Place Parts_Breadcrumbs="-" />
</Match>
Author is a custom content type I've created and the Breadcrumbs Part is a custom part.
The breadcrumbs part is hidden, but the title is still displayed. If I inspect it with Shape Tracing it is definitely Parts_Title I want to remove, but the content of my placement file doesn't seem to work.
I do not have a whole of example to go on there, but it seems to me that this part is conflicting with the Parts_Title that ships with orchard.
Try extending the modifier in your placement as well as your shapes to something like:
Parts_MyModule_Title
This just adds some more clarity and can keep orchard from stepping all over itself.
Similar problem here.
This is because your custom part's Placement.info was loaded first and Orchard Title part was loaded after that overriding it.
To solve it, in your custom part's Module.txt, put a dependence on Title. This will force Orchard Title to be loaded first before your custom part.

trying to remove login url from header / change evaluation order of layout updates

I want to remove the login url from the header, but magento won't budge. In the local.xml file I have the following code:
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
</reference>
After a little debugging I found that the login url is added AFTER it is "removed" (customer.xml:75 of the base/default theme.
How can I change the order in which layout updates are processed? Surely the local.xml is supposed to override just about anything?
edit:
Just to be clear, I am building a theme, so editing existing files is not an option for me.
You'd think that, but it gets tricky. You didn't mention it in your post, but what handle tag are you putting your reference tag in? The base custoemr.xml file that adds the customer/getLoginUrl is run from the customer_logged_out handle. Even if your code's in local.xml, if it's in a default handles or full action name handle, it will run after the code in catalog.xml because local.xml only wins on a per handle.
If that didn't make sense, just add this to your local.xml and you should be good to go.
<customer_logged_out>
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
</reference>
</customer_logged_out>

OrchardCMS layout of admin pages

I'm trying to change the layout of the admin page for a type and I'm struggling. The client is very specific on the order of the fields and I'm not sure how to do it.
I've created an admin theme and changed the placement.info, but it doesn't seem to work. Are there any hooks I could use to accomplish this?
Any help much appreciated.
My placement.info in the admin theme.
<Match ContentType="Course">
<Place Parts_Routable_Edit="Content:1" />
<Place Fields_Contrib_TaxonomyField_Edit="Content:2" />
<Place Parts_Taxonomies_Term_Fields="Content:2.5" />
<Place Parts_MediaPickerField_Edit="Content:3" />
<Place Parts_Course_Edit="Content:4" />
<Place Parts_Tags_Edit="Content:5" />
</Match>
There's also another problem. I would like 3 taxonomies, and have them placed in different areas of the admin screen. Any idea how to do that?
Since 1.5, you can change the order of parts and fields in the editor, from the admin dashboard. Go to Content Types, select the type, then click on "Manage Placement". You can then drag and drop parts and fields around.
Note that admin themes need to contain a IThemeSelector implementation that gives it a priority of more than 100, which is the priority of the default admin theme.
It really depends on what you want to change. A lot of the admin stuff uses regular ASP MVC, so all you really need to do is override a view or a couple of shapes.
For instance, if you wanted to change how the Modules page was rendered, you could do the following:
Create the folder Views/Orchard.Modules/Admin (this matches the module/controller name) in your theme. Inside it create a view called Index.cshtml, and copy and paste the code from the same view in Orchard.Modules - now you can change your version as much as you like and it should override the default view.
For overriding shapes it is a case of just working out the shape name via the shape tracing module and then adding your own version in your Views folder.
All this is fairly generic advice though, again it really does depend on exactly what you want to change.

Resources