How to override an existing interface implementation in Orchard? - orchardcms

I'd like to create a custom ILayoutManager in my module for Orchard CMS:
CustomLayoutManager : ILayoutManager
And I want to override the exiting ILayoutManager (in Orchard.Layouts module) implementation.
But I don't know which Orchard API I can use to do it, how can I enforce Orchard to use my implementation?
Thanks!

[OrchardSuppressDependency("Orchard.Autoroute.Services.AutorouteService")]
public class SbSiteGovernModule : Module {
builder.RegisterType<MyAutorouteService>().As<IAutorouteService>();
}

Related

Is there a way to prevent creation of a data class item in C# WindowsForms UserControl

If I create a UserControl, to create and edit an instance of a data class e.g. Person in C# WindowsForms (call it PersonControl), the framework automatically adds an instance of Person in PersonControl.Designer with some default values for the properties and fills the item controls with those values. This behavior has a number of side effects which I would like to avoid.
Question: is there a defined way to prevent creation of a data class instance in UserControl.Designer?
I think you missing the DesignerSerializationVisibility attribute. If you have a custom control every public property that you add will automatically be serialized. You can use this attribute to disable the serialization for a property. I also recommend to add the Browsable attribute which will hide the property from the designer. If you want more control over serialization, like you want to serialize only when another property is set to true you can create a special named method which will then called by the designer Defining Default Values with the ShouldSerialize and Reset Methods. There was a MSDN Magazine where a lots of winform learning resource was relased there are some gems about winform internal working. If you interested in you can quickly look trhrough it. My favorite is. Create And Host Custom Designers With The .NET Framework 2.0
Sorry but i didn't mention another attribute DefaultValue You can use the attribute the following way.
public partial class PersonEditControl : UserControl
{
[DefaultValue(null)] // This attribute tells the designer if the property value matches what we specified in the attribute(null) it should not store the property value.
public PersonData? Person { get; set; }
public PersonEditControl()
{
InitializeComponent();
}
}

How to override a class in liferay 7/DXP. the class inside the modules/ foundation?

Is there any way to override class inside the modules/foundation in liferay DXP?
Liferay 7 design is more over extensible than override. Instead of overriding something extend the functionality or replace with another module.
Here's are few samples which allow us to extend at different level.
https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/extensions
https://github.com/liferay/liferay-blade-samples/tree/master/liferay-workspace/overrides

Custom UIControl does not show up in toolbox

I am trying to implement a custom control to have a reusable component that can be used in several view controllers. I followed this tutorial from Xamarin:
custom controls
unfortunately the control does not show up in IOS Designer's toolbox. How can i make it showing up?
I'll answer my own question:
The problem was that i needed to add a constructor like this:
public YourControlClass(IntPtr p)
: base(p)
{
...
}

Overriding editor template in theme affects admin view

I created a form using the CustomForms module and need to control the markup of the input fields I've included on the form (to add bootstrap specific classes). I added a view to my theme at the location /Views/EditorTemplates/Fields/Input.Edit.cshtml and that allowed me to update the markup for the input fields.
My problem is that the view in my theme is also being picked up in the admin views. I didn't expect this behavior but it's happening. I tried scoping the view override to the url (Input.Edit-url-contact.cshtml) and content type (Input.Edit-ContactRequest.cshtml) using the alternate naming conventions but they do not appear to work in this case.
Is there a way to scope the Input.Edit.cshtml view in my theme so it only applies to the front-end of the site? Or is there a better way to achieve what I'm trying to do?
I ended up working around this issue by implementing a shape table provider (based on Bertrand's suggestion) to specify different template names in my theme so they weren't picked up in the admin. Here's what it looks like:
public class EditorFieldShapeProvider : IShapeTableProvider
{
public void Discover(ShapeTableBuilder builder)
{
builder.Describe("EditorTemplate")
.OnDisplaying(displaying =>
{
var shape = displaying.Shape;
if (shape.ContentField is InputField) {
shape.TemplateName = "CustomInputField";
}
});
}
}
Just drop that class somewhere in your theme and create your view at /ThemeName/Views/EditorTemplates/CustomInputField.cshtml

inheriting a GUI class in LWUIT 1.5

I'm trying to inherit a class that I made in the GUI Resource Editor of Lwuit to extend some functionality. I want to do something like:
public class MyCustomGUIForm extend CustomGUIForm{...}
Where CustomGUIForm its a Form that I create in the Resource Editor. Any idea??
I am going to explain you what I do for extend some functionallity in the Formsthat I create with the Resource Editor.
When you build a NetBeansProject with the Resource Editor, you get a StateMachine class wich allows you to modify/add some aspects of your apps navigation.
In the StateMachine class you can find a lot of methods related to the elements that you create in the Resource Editor.
For example:
You create a Form in the Resource Editor, called CustomGUIForm. After you save the .res, you should find some methods in the StateMachine class called beforeCustomGUIForm postCustomGUIForm and exitGUIForm, with this methods you can use the Form and add some functionality. You can observe that in StateMachine there are other methods for Commands that you build in the Resource Editor, ActionListeners, etc etc. Take a look to the overriden methods for the StateMachine, they could be usefull for you.
Let me know if you have more questions
While jmunoz gave the better answer for this just for completeness you can indeed inherit and override any component created by the resource editor.
In your Statemachine override:
protected Component createComponentInstance(String componentType, Class cls) {
if(cls == Form.class) {
return new MyFormInstance();
}
return null;
}
There is one drawback in this approach, all forms will now be MyFormInstance. This is or usable for some use cases and not so much for others.

Resources