Creating ContentPart_Edit Shape using ShapeResult to support placement, Swagger module - This week in Orchard (14/04/2022)

Gábor Domonkos's avatar
Placement, Documentation, This week in Orchard, Content field

This week you can read about updating the Roles module documentation, creating ContentPart_Edit Shape using ShapeResult to support placement, fixing an NRE when trying to save an empty LinkField and a demo of a Swagger module for Orchard Core! Are you interested in the details? Check out this post for more!

Orchard Core updates

Update Roles module documentation

Orchard doesn't actually "come with predefined roles". The roles themselves are actually not created anywhere by default. Permissions corresponding to them are but without roles, they don't do anything. The roles all just come from recipes.

Szabolcs Deme updated the description of the documentation to reflect that.

Update Roles module documentation

Create ContentPart_Edit Shape using ShapeResult to support the placement

In the past, when the placement was defined for ContentPart_Edit none of the following applied.

{
   "ContentPart_Edit": [
   {
      "place": "-",
      "contentType": [ "Container" ]
   } ],
   "BackgroundColor_Edit": [
   {
      "place": "-",
      "contentType": [ "Container" ]
   } ],
   "BootstrapColor_Edit": [
   {
      "place": "-",
      "contentType": [ "Container" ]
   } ]
}

If you want to reproduce the behavior, you can follow these steps:

  1. Create part BootstrapColor with TextField with PredefinedList as editor.
  2. Select Reusable.
  3. Add BootstrapColor Part as named part to Container content type with name BackgroundColor.
  4. Add any of the following placement rules in placement.json to hide:
    "ContentPart_Edit": [ { "place": "-", "contentType": [ "Container"], "contentPart" : ["BootstrapColor"], "differentiator": "BackgroundColor" } ] OR
    "BootstrapColor_Edit": [ { "place": "-", "contentType": [ "Container"], "contentPart" : ["BootstrapColor"], "differentiator": "BackgroundColor" } ] OR
    "BootstrapColor": [ { "place": "-", "displayType": "Edit", "contentType": [ "Container"], "contentPart" : ["BootstrapColor"], "differentiator": "BackgroundColor" } ]
  5. See part is still visible while editing and placement rule is not applied, but the expected behavior is the placement should apply.

So, this is about creating ContentPart Shape using ShapeResult to support placement and alternates. Now, placement can be applied to dynamic named parts as follows:

{
   "ContentPart_Edit": [
   {
      "place": "Parts#HTML Attributes",
      "differentiator": "Container-BackgroundColor",
      "contentType": ["Container"],
      "contentPart": ["BootstrapColor"]
   }]
}

and shape can be overridden using alternates, eg. ContentPart-Container-BackgroundColor.Edit.cshtml.

Fix NRE when trying to save an empty LinkField

Content items with optional Link Fields don't allow the Link Field URL to be cleared once saved due to a Null exception in the display driver. The expected behavior would be when a Link Field that is set to Optional has its values cleared, the Link Field should remain empty when saved.

You could reproduce the behavior by following these steps:

  1. Create a content type with a Link Field and leave it Optional.
  2. Create a new instance of that type and fill in a URL and Link Text then save.
  3. Edit the previously created instance, clear the URL and Link Text, and then save again.
  4. Edit the previously saved instance, and the URL and Link Text will still be there.
  5. Check the Orchard logs - there will be a Null exception from the display driver.

As you can see from the changes below, now we only validate the URL if it exists.

Fix NRE when trying to save an empty LinkField

Demos

Swagger Module

Hisham Bin Ateya has an organization on GitHub called OrchardCore Contrib with a couple of projects under it. The OrchardCoreContrib.Modules repository contains several modules. This demo is about checking how you can use the Swagger Module.

Swagger is an Interface Description Language for describing RESTful APIs expressed using JSON. Swagger is used together with a set of open-source software tools to design, build, document, and use RESTful web services. Swagger includes automated documentation, code generation (into many programming languages), and test-case generation.

The point here is that this module provides easy integration. So, if you add the OrchardCoreContrib.Apis.Swagger NuGet package to your Orchard Core host project and run your application, you will find two new features if you search for the swagger word in the Configuration -> Features screen.

The new Swagger features

If you enable them then you get a Swagger JSON-based API documentation by visiting the Swagger end-point by append /swagger/v1.0.0/swagger.json to the URL.

Swagger JSON based API documentation

And the same thing is also available under the /swagger/index.html URL with a nice Swagger UI. This - just as Swagger does - automatically shows all registered API endpoints, so if you add documentation to them, those will show up here. And of course, you can play with them as you can do with Swagger in any context.

The Swagger UI

If you would like to know more, head to YouTube for a short demonstration of this module!

News from the community

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 247 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this Orchard meeting!

No Comments

Add a Comment