Orchard CMS adding fields to page in custom recipe? - orchardcms

Is there any way to have a custom recipe add some text and image fields to the page? It looks like part of the recipe handles commands, but I can't find any commands that do this at # http://docs.orchardproject.net/Documentation/Using-the-command-line-interface
Update
Thanks for the response Bertrand, but there are some issues with that.
I exported everything for a recipe from a tenant that has 1. added fields, 2. added parts to the Page along with 3. an added List and 4. an added container widget to the Default layer that shows the list.
<Metadata>
<Types>
<Page ContentTypeSettings.Draftable="True" TypeIndexing.Included="true">
<TagsPart />
<LocalizationPart />
<TitlePart/>
<AutoroutePart />
<ContainablePart />
<AmazonProductsPart />
<YouTubeVideosPart />
</Page>
</Types>
<Parts>
<BodyPart BodyPartSettings.FlavorDefault="html" />
<Page ContentPartSettings.Attachable="True">
<Thumbnail.ImageField DisplayName="Thumbnail" ImageFieldSettings.MaxHeight="75" ImageFieldSettings.MaxWidth="75" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="True" ImageFieldSettings.ResizeAction="Validate" />
<PageImage.ImageField DisplayName="PageImage" ImageFieldSettings.MaxHeight="250" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="True" ImageFieldSettings.ResizeAction="Resize" />
<PreContent.TextField DisplayName="PreContent" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" TextFieldSettings.Flavor="Html" TextFieldSettings.Required="False" />
<PostContent.TextField DisplayName="PostContent" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" TextFieldSettings.Flavor="Html" TextFieldSettings.Required="False" />
</Page>
</Parts>
</Metadata>
...
<Data>
<List Id="/alias=page-list" Status="Published">
<CommonPart Owner="/User.UserName=admin" CreatedUtc="2012-05-26T22:52:20Z" PublishedUtc="2012-05-26T22:57:37Z" ModifiedUtc="2012-05-26T22:57:37Z" />
<AutoroutePart Alias="page-list" UseCustomPattern="false" />
<AdminMenuPart AdminMenuPosition="2" OnAdminMenu="false" />
<MenuPart MenuText="Page List" MenuPosition="3" OnMainMenu="false" />
<ContainerPart ItemContentType="Page" ItemsShown="true" Paginated="true" PageSize="10" OrderByProperty="CommonPart.CreatedUtc" OrderByDirection="1" />
<TitlePart Title="Page List" />
</List>
<ContainerWidget Id="" Status="Published">
<CommonPart Owner="/User.UserName=admin" Container="/Layer.LayerName=Default" CreatedUtc="2012-05-26T22:55:42Z" PublishedUtc="2012-05-26T22:55:42Z" ModifiedUtc="2012-05-26T22:55:42Z" />
<WidgetPart Title="Page List" Position="1" Zone="AsideFirst" RenderTitle="false" />
<ContainerWidgetPart Container="/alias=page-list" PageSize="5" OrderByProperty="CommonPart.CreatedUtc" OrderByDirection="1" ApplyFilter="false" FilterByProperty="CustomPropertiesPart.CustomOne" FilterByOperator="=" />
</ContainerWidget>
</Data>
I then inject that into a copy of the default recipe with the appropriate modules activated.
When creating a new tenant from that recipe,
All the modules are enabled, good
The list is created, good
The page has the added parts, good
The page does not have the added fields, bad
The container widget does not exist, bad
It looks like the part fields are not added, and the widget was not created.
I did another simple test, and it looks like a bug?
Repro Steps:
Add fields to the page
Add a widget
Export everything
delete the widget
Import the exported xml
Expected: The widget to be back
Actual: the widget is still missing
is the recipe suppose to honor page fields and widgets, did I do something wrong, or is this a bug?
Update
Okay, this has to be a bug. When manually adding the fields, I get this message even though it isn't showing the fields: "A field with the same name already exists."

You don't need a command, this is supported by recipes without that. The easiest way to get an example is to add a field from the admin UI, and then export the metadata and examine the recipe that created.

Related

CRM2011: create a role that is able to delete invoice products, but not able to delete the invoice

Is that possible to define a security role that is not able to delete any invoice but able to delete invoiceproduct of any invoice?
The environment is not customized, and the definition( Tab:Mscrm.Form.invoicedetail.MainTab-->Group:Mscrm.Form.invoicedetail.MainTab.Groups-->Group:Mscrm.Form.invoicedetail.MainTab.Save-->Controls:Mscrm.Form.invoicedetail.MainTab.Save.Controls) for the ribbon button is
<Button Id="Mscrm.Form.invoicedetail.Delete" ToolTipTitle="$Resources:Mscrm_Form_Other_MainTab_Management_Delete_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Ribbon.Form.Tooltip.Delete" Command="Mscrm.DeletePrimaryRecord" Sequence="70" LabelText="$Resources:Ribbon.HomepageGrid.MainTab.Management.Delete" Alt="$Resources:Ribbon.HomepageGrid.MainTab.Management.Delete" Image16by16="/_imgs/ribbon/Delete_16.png" Image32by32="/_imgs/Workplace/remove_32.png" TemplateAlias="o2" ModernImage="Remove" />
And the corresponding Command Definition is
<CommandDefinition Id="Mscrm.DeletePrimaryRecord">
<EnableRules>
<EnableRule Id="Mscrm.FormStateNotNew" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
<EnableRule Id="Mscrm.CanDeletePrimary" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.DeletePrimaryEntityPermission" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="onActionMenuClick" Library="/_static/_forms/form.js">
<StringParameter Value="delete" />
<CrmParameter Value="PrimaryEntityTypeCode" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
It seems it is not able to create such a role meet the requirement.
because
1. In the 'displayrule' section, it needs 'Mscrm.DeletePrimaryEntityPermission' permission.
2. In the 'enablerule' section, it needs 'CanDeletePrimary' permission.
Thanks in advance
I believe that's not possible using OOB functions. I would suggest to develop the plugin that will handle Delete message of invoiceproduct and throw an exception if user doesn't have required role.

Wrong alias pattern when importing taxonomy terms

I'm trying to leverage Import/Export module to import taxonomies and taxonomy terms like so
<Orchard>
<Data>
<Taxonomy Id="/Identifier=Product-Categories" Status="Published">
<AutoroutePart Alias="eshop/categories" UseCustomPattern="false" />
<IdentityPart Identifier="Product-Categories" />
<TitlePart Title="Product Categories" />
<TaxonomyPart TermTypeName="ProductCategoriesTerm" />
</Taxonomy>
<ProductCategoriesTerm Id="/Identifier=Category-1" Status="Published">
<AutoroutePart UseCustomPattern="false" />
<IdentityPart Identifier="Category-1" />
<TitlePart Title="Test category" />
<TermPart Count="0" Selectable="true" Weight="1" TaxonomyId="/Identifier=Product-Categories" Path="" />
</ProductCategoriesTerm>
</Data>
</Orchard>
ProductCategoriesTerm when created through dashboard has default pattern
{Content.Container.Path}/{Content.Slug} ### my-taxonomy/my-term/sub-term
but importing terms makes them to use just {Content.Slug} ... How do I instruct AutoroutePart to use the default pattern? Tried UseCustomPattern="false" or exclude AutoroutePart with no effect it's just test-category instead of eshop/categories/test-category and won't regenerate even if if I set AutouroutePart to automatically regenerate when editing content and disable custom patterns and it won't revert to default pattern even if I try to publish it through dashboard.
Also it's mandatory to include "Count" for the TermPart when importing, does it affect anything? Sounds like something that should be dynamic and relevant only with export.
When importing taxonomy terms (and I guess any other part that has a container) it's necessary to specify Container for the common part. Without it Container for the part is null and therefore can't resolve {Content.Container.Path} in the alias pattern.
<CommonPart Container="/Identifier=Product-Categories" />
Or if it's nested term then Container is the parent term.

Adding Custom Content Items in Orchard Site Recipe

I have added a content type in my custom orchard recipe but when I try to create an instance of that content type within the recipe nothing happens.
Declaration:
<Metadata>
<Types>
<Speedbump ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" TypeIndexing.Indexes="Search">
<TitlePart />
<BodyPart />
<CommonPart />
</Speedbump>
</Types>
<Parts>
<BodyPart BodyPartSettings.FlavorDefault="html" />
</Parts>
</Metadata>
Creation:
<Command>
Speedbump create /Slug:"valid-url" /Title:"Valid URL" /Path:"valid-url" /Homepage:false /Publish:true /UseWelcomeText:false
</Command>
Any ideas as to why this isn't working? I can go into the site after it is created and my speedbump type is defined and creatable but the instance that should have been created by the recipe doesn't exist. Thank you.
This isn't how you create content items in recipes. You add xml in the <Data> tag like so:
<Data>
<Speedbump Id="" Status="Published">
<BodyPart Text="Hello this needs to be encoded" />
<CommonPart Owner="/User.UserName=admin" CreatedUtc="2014-09-05T16:09:13Z" PublishedUtc="2014-09-05T16:15:43Z" ModifiedUtc="2014-09-05T16:15:43Z" />
<TitlePart Title="My Page" />
</Speedbump>
</Data>
For any custom parts, you will need to implement Import and Export functions in your driver method. Check core modules for good examples

EntityRule in subgrid on custom entity not working

I tried to add a button to connection subgrid ribbon. This button should only be visible if the primary entity equals 'new_visitreport'.
Here is my try:
<CustomAction Id="Visitreports.connection.customAction"
Location="Mscrm.SubGrid.connection.MainTab.Management.Controls._children"
Sequence="15" >
<CommandUIDefinition>
<Button Id="Mscrm.SubGrid.connection.AddXYZ"
ToolTipTitle="$LocLabels:Button.AddXYZ.Label"
ToolTipDescription="$LocLabels:Button.AddXYZ.Tooltip"
LabelText="$LocLabels:Button.AddXYZ.Label"
Command="Button.AddXYZ.Command"
Image16by16="$webresource:new_XYZ_16"
Image32by32="$webresource:new_XYZ_32"
TemplateAlias="o1" />
</CommandUIDefinition>
</CustomAction>
<CommandDefinition Id="Button.AddXYZ.Command">
<EnableRules></EnableRules>
<DisplayRules>
<DisplayRule Id="EntityEqualsVisitreport" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="openDialog"
Library="$webresource:new_script_open_dialog">
<StringParameter Value="3EEE3AE1-5543-433E-8123-6A14EA925A96" />
<StringParameter Value="3EEE3AE1-5543-433E-8123-6A14EA925A96" />
<BoolParameter Value="false" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<DisplayRule Id="EntityEqualsVisitreport">
<EntityRule AppliesTo="PrimaryEntity"
EntityName="new_visitreport" />
</DisplayRule>
It seems that this rule always returns false. If I remove the display rule from command definition the button is visible, but independet of the currently primary entity.
Is there any mistake in my examply or is it not working for custom entitis although it is supported? (MSDN article)
Try using FormEntityContextRule it looks like these guys had the same issue you had. Forum Link
<FormEntityContextRule EntityName="account"/>

Orchard Recipe Add Page - Image Base Url

I am trying to add a page (homepage) in an orchard recipe that contains an image in HTML. However, the full URL of the image is dependent upon the deployment.
How can I use the base URL of the site in the recipe?
So far I've got this:
<Data>
<Page Id="/alias=" Status="Published">
<BodyPart Text="<p><img alt="" src="~/Media/Default/Page/Homepage.png" width="100%" /></p>" />
<CommonPart Owner="/User.UserName=admin" />
<AutoroutePart Alias="/" CustomPattern="/" UseCustomPattern="true" />
<TitlePart Title="Home" />
</Page>
</Data>
But the normal ~ doesn't resolve to the base url.
Ideas?
Recipes don't support tokens or dynamic values, but that would definitely be a nice feature.
For now you will either have to implement such functionality yourself, or you could leave the url as is (starting with the tilde), and implement an IHtmlFilter that will actually process relative values at runtime.

Resources