Sitecore 8 MVC : How to make the field editable in Page Editor - sitecore

I'm trying to make my Sitecore site compatible with page editor i.e. all the fields text, rich text editor, etc, should be able to be updated in Page Editor.
So far I've modified the TDS T4 template which returns a HTMLString for each field like below:
public HtmlString HeroImageField(bool isEditable = true, string parameters = "")
{
string renderParameter = GenerateRenderParameter(isEditable, parameters);
return new HtmlString(Sitecore.Web.UI.WebControls.FieldRenderer.Render(
Sitecore.Context.Database.GetItem(this.EntityId.ToString()), "Hero Image", renderParameter ));
}
So, in view I just call Model.HeroImage()
Is there a better way to achieve above? Maybe Glass Mapper comes with out of box support for this (which I don't know).

Sitecore comes with MVC helpers that you can use to make fields editable:
#Html.Sitecore().Field("My Field Name") //Context item by default
#Html.Sitecore().Field("My Field Name", Model.PageItem) //Explicit page item
#Html.Sitecore().Field("My Field Name", Model.Item) //Datasource item (may be context item)
My recommendation is also to use a controller to load a different view for editing. There is often a different visual needed for authoring fields. Carousels/tabs should be flattened out, validation messages need to be exposed, etc.
See more at:
http://sitecore-community.github.io/docs/sitecore-mvc/rendering-content/

Glass mapper has something OOTB for that. You can use the extended WebViewPage GlassView and use the Editable methods as described here:
http://glass.lu/Mapper/Sc/Tutorials/Tutorial14

Related

Acumatica-LotSerialNbrAttribute screen on mobile app

I'm using Acumatica customization Acumatica-LotSerialNbrAttribute
This customization adds a new screen for look for InventoryID and LotSerialNbr and visualize its attributes.
I'm trying to add this window to the acumatica mobile app.
Here my code:
add screen IN202501 {
add container "InventoryLotSerialContainers" {
add field "InventoryID"
add field "LotSerialNbr"
add group "Attributes" {
displayName = "Attributes"
collapsable = True
add attributes "AttributesAttributes"
}
add recordAction "Save" {
behavior = Save
}
add recordAction "Cancel" {
behavior = Cancel
}
attachments {
}
}
}
And the screen is visible on the mobile app with the 2 selectors
Then I select Inventory and when I select Lot Serial Nbr, the first selector is in blank, causing that I can't review the attributtes neither save the information.
Here the InventoryID selector in blank.
Hope you can help me to successfully publish this screen on acumatica mobile app.
Thanks.
Attributes are a grid style representation in Acumatica. That means you need a container that will show multiple records. I'm getting rusty on mobile pretty quickly, but I believe your definition is set to display a single value value only.
Try adding a separate container for attributes:
add container "AttributesAttributes" {
add field "Attribute"
add field "Value"
}
This should open into a view of multiple records, showing all of your attributes. By specifying the Attribute and Value fields, you should see both data elements in the container.

Acumatica - How to change the page opened by the edit button (pencil)

I'm trying to customize a page so that the edit button (the pencil icon one) directs the user to a specific page. In my case, the edit button is linked to a BAccountID field :
By default, it opens the Business Account's page (page CR303000):
I would like it to open a different page that I created that has a similar BAccount view (page AR303001) :
Can this be done ? And how ? I can't seem to find the code behind this logic.
The target graph is declared in the PXPrimaryGraph attribute decorating the DAC.
BAccount DAC is a special case that uses a more complex attribute (CRCacheIndependentPrimaryGraphList) that inherits from PXPrimaryGraph.
[CRCacheIndependentPrimaryGraphList(new Type[]{
typeof(CR.BusinessAccountMaint),
typeof(EP.EmployeeMaint),
typeof(AP.VendorMaint),
typeof(AP.VendorMaint),
typeof(AR.CustomerMaint),
typeof(AR.CustomerMaint),
typeof(AP.VendorMaint),
typeof(AR.CustomerMaint),
typeof(CR.BusinessAccountMaint)},
new Type[]{
typeof(Select<CR.BAccount, Where<CR.BAccount.bAccountID, Equal<Current<BAccount.bAccountID>>,
And<Current<BAccount.viewInCrm>, Equal<True>>>>),
typeof(Select<EP.EPEmployee, Where<EP.EPEmployee.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AP.VendorR, Where<AP.VendorR.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AP.Vendor, Where<AP.Vendor.bAccountID, Equal<Current<BAccountR.bAccountID>>>>),
typeof(Select<AR.Customer, Where<AR.Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AR.Customer, Where<AR.Customer.bAccountID, Equal<Current<BAccountR.bAccountID>>>>),
typeof(Where<CR.BAccountR.bAccountID, Less<Zero>,
And<BAccountR.type, Equal<BAccountType.vendorType>>>),
typeof(Where<CR.BAccountR.bAccountID, Less<Zero>,
And<BAccountR.type, Equal<BAccountType.customerType>>>),
typeof(Select<CR.BAccount,
Where2<Where<
CR.BAccount.type, Equal<BAccountType.prospectType>,
Or<CR.BAccount.type, Equal<BAccountType.customerType>,
Or<CR.BAccount.type, Equal<BAccountType.vendorType>,
Or<CR.BAccount.type, Equal<BAccountType.combinedType>>>>>,
And<Where<CR.BAccount.bAccountID, Equal<Current<BAccount.bAccountID>>,
Or<Current<BAccount.bAccountID>, Less<Zero>>>>>>)
},
VerifyRightsBy = new [] { typeof(CR.BusinessAccountMaint) })]
There is no way to easily customize this attribute. To change it would you need to replace the BAccount DAC with another one. The preferred method for your use case is to avoid usage PXPrimaryGraph attribute by using a regular action button.
The action button can be configured to show the pencil icon:
Make PXButton appear as pencil icon
And it can be displayed beside the field using PXLayout Merge property or you can use LinkCommand to redirect:
https://stackoverflow.com/a/60446714/7376238

Sitecore, render Item in code with personalization in mvc

My terminology might be slightly off as I am new to Sitecore mvc. I am trying to hardcode a view rendering with a hard coded datasource (I have to do it this way for other requirements) This view rendering has placeholders that are dynamically set and then personalized.
How can I trigger the ViewRendering on an item?
I've tried ItemRendering, but it doesn't seem to be picking up the stuff set up in the PageEditor.
* To be clear, the helpful posts below have the rendering working, but we do not seem to be getting the personalized datasources. *
I believe this is what you're after:
Item item = /* think you already have this */;
// Setup
var rendering = new Sitecore.Mvc.Presentation.Rendering {
RenderingType = "Item",
Renderer = new Sitecore.Mvc.Presentation.ItemRenderer.ItemRenderer {
Item = item
}
};
rendering["DataSource"] = item.ID.ToString();
// Execution
var writer = new System.IO.StringWriter();
var args = new Sitecore.Mvc.Pipelines.Response.RenderRendering(rendering, writer);
Sitecore.Mvc.Pipelines.PipelineService.Get().RunPipeline("mvc.renderRendering", args);
// Your result:
var html = writer.ToString();
You can statically bind a View Rendering using the Rendering() method of the Sitecore HTML Helper. This also works for Controller Renderings using the same method.
#Html.Sitecore().Rendering("<rendering item id>")
This method accepts an anonymous object for passing in parameters, such as the Datasource and caching options.
#Html.Sitecore().Rendering("<rendering item id>", new { DataSource = "<datasource item id>", Cacheable = true, Cache_VaryByData = true })
In your view rendering, I am assuming you have a placeholder defined along with the appropriate placeholder settings in Sitecore (If not, feel free to comment with more detail and I will update my answer).
#Html.Sitecore().Placeholder("my-placeholder")
In this case, "my-placeholder" will be handled like any other placeholder, so you will be able to add and personalize components within it from the Page Editor.

Overriding Admin shapes in custom Orchard CMS theme

I'm doing a custom theme for Orchard CMS.
As part of client project one of the requirements is to have some extra functionality in blog admin page.
This is pretty easy doing some simple changes in Parts.Blogs.BlogPost.ListAdmin.cshtml
I do not want to change the Blog source code, I would like to override that wiew in theme just like I'm doing with all the others on front end.
Following some guidelines found on orchard forum I have tried the following paths:
~/Themes/MyTheme/Views/Parts.Blogs.BlogPost.ListAdmin.cshtml
~/Themes/MyTheme/Views/Orchard.Blogs/Parts.Blogs.BlogPost.ListAdmin.cshtml
~/Themes/MyTheme/Views/Dashboard/Admin/Parts.Blogs.BlogPost.ListAdmin.cshtml
but the view is not picked up.
So, How may I override a view in my theme that will be picked up by admin dashboard instead of the default one?
Thanks
You need to create a theme with a project file, then add a .cs file with something like this in it:
public class AdminOverride : IThemeSelector
{
public ThemeSelectorResult GetTheme(RequestContext context)
{
if (AdminFilter.IsApplied(context))
{
return new ThemeSelectorResult { Priority = 111, ThemeName = "NewAdminTheme" };
}
return null;
}
}
Don't set this theme as current though, just enable it from the backend. You will also need to set your TheAdmin as the base theme in the Theme.txt like this:
BaseTheme: TheAdmin

How to get a reference to the currently edited item when inside a custom field in Sitecore

In Sitecore I have created a custom field (via this recipe: http://sdn.sitecore.net/Articles/API/Creating%20a%20Composite%20Custom%20Field/Adding%20a%20Custom%20Field%20to%20Sitecore%20Client.aspx)
The field is for use in the content editor.
The custom field has a menuitem attached (the little textbutton rendered just above the field)
The custom field work as expected and the menuitem hooks into code in the custom field class as it should. However, the logic I need to implement for the menuitem requires that I get a reference to the item that is currently being edited by the user in the content editor.
However, to my surprise this doesn't work:
Sitecore.Context.Item
This does not give me the item that the user is currently editing, but instead the "content editor" item, which is always the same.
I would think there would simply be a property of some object in the API, but I can't find it.
If you are following this article then you will have defined a property on your control..
public string ItemID { get; set;}
.. this will be populated with the ID for the item you are editing. You should be able resolve the Item object from this ID using something like:
Sitecore.Data.Database.GetDatabase("master").GetItem(ItemID)
.. if you are just looking just for the value of the field you are editing you can use the base.Value field.
The best place to ask this would be on the developer forum, you should get a good response on there.
Though, taking a look through the Sitecore code, it looks like this might be what you want. Try reading it from the ViewState:
public string ItemID
{
get
{
return base.GetViewStateString("ItemID");
}
set
{
Assert.ArgumentNotNullOrEmpty(value, "value");
base.SetViewStateString("ItemID", value);
}
}
Stephen Pope is right, though there are more properties that you can 'automagiacally' retrieve from Sitecore. Some properties, just like ItemID are put on the field via reflection. There's also the ItemVersion and Source that can be useful for your custom controls.
If you're intereseted, take a peek inside the class Sitecore.Shell.Applications.ContentEditor.EditorFormatter, and especially its method SetProperties:
ReflectionUtil.SetProperty(editor, "ItemID", field.ItemField.Item.ID.ToString());
ReflectionUtil.SetProperty(editor, "ItemVersion", field.ItemField.Item.Version.ToString());