Sitecore Layout Parameters Error - sitecore

Currently getting an InvalidOperationException on loading 2 sublayout parameters on a rendering to change their values. They are named "Title" and "Text" respectively and both are single-line text boxes. I am able to change the parameters on the same item but different rendering. The other rendering contains a general link and an image.
Anyone run into this and able to shed a bit of light?
[InvalidOperationException: field]
Sitecore.Data.FieldDescriptor..ctor(Item item, String fieldName) +221
Sitecore.Shell.Applications.Layouts.DeviceEditor.RenderingParameters.GetAdditionalParameters(List`1 fieldDescriptors, Item standardValues, Dictionary`2 additionalParameters) +430
Sitecore.Shell.Applications.Layouts.DeviceEditor.RenderingParameters.GetFields(RenderingDefinition renderingDefinition, Dictionary`2 parameters) +902
Sitecore.Shell.Applications.Layouts.DeviceEditor.RenderingParameters.Show() +266
Sitecore.Shell.Applications.ContentManager.Dialogs.LayoutDetails.LayoutDetailsForm.EditRenderingPipeline(ClientPipelineArgs args) +356

This exception is thrown by the code:
Field field = item.Fields[fieldName];
Assert.IsNotNull(field, "field");
It looks like either you haven't set the field name or you have a typo in a name field or the item does not have the field with a name you're passing as a parameter.

Related

Sitecore: Value cannot be null. Parameter name: uri

Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: uri
Source: Sitecore.Kernel
I was editing a placeholder item in a local
Sitecore 8.1 (rev. 151207) instance when I got this error. Now I can't edit, delete, or reset it (or its parent folders). I also can't read the item in the content editor as the error pops up when I click on the parent folder. I've tried deleting/editing it and it's parent folder from the content editor, through code, and through PowerShell commands but the same error always shows.
I've also tried replacing my configs and bin folders with my backup copies, clearing cache, restarting IIS and the app pool, but nothing has helped.
I'm completely stuck. Does anyone know how to fix this?
Edit:
The full error in the logs is:
Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: uri
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Data.ItemUri..ctor(ItemUri uri)
at Sitecore.Data.Items.Item.GetItemUriFromSourceItem()
at Sitecore.Data.Items.Item.get_SourceUri()
at Sitecore.Data.Items.Item.get_Source()
at Sitecore.Data.Fields.Field.GetSourceItem()
at Sitecore.Data.Fields.Field.GetInheritedValue(Boolean allowStandardValue)
at Sitecore.Pipelines.GetFieldValue.GetInheritedValue.Process(GetFieldValueArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Data.Fields.Field.GetValue(Boolean allowStandardValue, Boolean allowDefaultValue, Boolean allowFallbackValue, Boolean allowInheritValue, Boolean allowInnerValue)
at Sitecore.Pipelines.ItemProvider.GetItem.GetLanguageFallbackItem.IsItemFallbackEnabled(Item item)
at Sitecore.Pipelines.ItemProvider.GetItem.GetLanguageFallbackItem.Process(GetItemArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Data.Managers.PipelineBasedItemProvider.ExecuteAndReturnResult[TArgs,TResult](String pipelineName, String pipelineDomain, Func`1 pipelineArgsCreator, Func`1 fallbackResult)
at Sitecore.Data.Managers.ItemManager.GetItem(ID itemId, Language language, Version version, Database database, SecurityCheck securityCheck)
at Sitecore.Nexus.Data.DataCommands.GetChildrenCommand.Execute(Item )
at Sitecore.Data.Engines.EngineCommand`2.Execute()
at Sitecore.Data.Managers.ItemProvider.GetChildren(Item item, ChildListOptions options)
at Sitecore.Data.Managers.ItemProvider.GetChildren(Item item, SecurityCheck securityCheck, ChildListOptions options)
at Sitecore.Data.Managers.PipelineBasedItemProvider.ExecuteAndReturnResult[TArgs,TResult](String pipelineName, String pipelineDomain, Func`1 pipelineArgsCreator, Func`1 fallbackResult)
at Sitecore.Data.Managers.PipelineBasedItemProvider.GetChildren(Item item, SecurityCheck securityCheck)
at Sitecore.Collections.ChildList.Populate(ChildListOptions options)
at Sitecore.Shell.Framework.Pipelines.DeleteItems.GetItemClones(Item item, Boolean processChildren)
at Sitecore.Shell.Framework.Pipelines.DeleteItems.GetItemClones(Item item, Boolean processChildren)
at Sitecore.Shell.Framework.Pipelines.DeleteItems.GetItemClones(List`1 items)
at Sitecore.Shell.Framework.Pipelines.DeleteItems.GetCheckCloneLinksMessage(List`1 items)
at Sitecore.Shell.Framework.Pipelines.DeleteItems.CheckCloneLinks(ClientPipelineArgs args)
The exception you provided occurs because you have nonempty invalid value in the __Source Item - {19B597D3-2EDD-4AE2-AEFE-4A94C7F10E31} field in your item. __Source Item is responsible for storing the original item URI for the clone items.
I don't know how you achieved that because there is a processor ValidateCloneSourceModifications in the saveItem pipeline that prevents of saving items with invalid __Source Item field.
I was able to reproduce your exception by changing the field value in the DB.
How to fix:
Find you broken field in the master DB -> SharedFields table. The FieldId is '19B597D3-2EDD-4AE2-AEFE-4A94C7F10E31'.
Fix it. It should be something like sitecore://master/{AE76A034-9491-4B83-99F5-39F227D6FB59}, where the ID is the original item id. You could also just set '' as a value, but it will remove the binding to the original item.
Clear cache.
It must help.
You can try the DB Browser /sitecore/admin/dbbrowser.aspx with this tool you can also delete items.
If this DB Browser admin tools fail, then I'm curious what's in the master database, check directly in sql what make this item special is than an option.

How to make Date Editable while using Glass mapper

Today i am facing one issue which has following requirement.
Date should be Editable.
Date should be in particular format.
My Code is like below which is not working.
foreach(var item in Model)
{
<div>#Editable(item, x => x.Start_Date.ToString("MMMM dd,yyyy"))</div>
}
I have tried following approach but throwing "DateParameters" namespace error.
#Editable(item, x=> x.Start_Date, new DateParameters { Format = "MMMM dd,yyyy"})
Also i have learner following thing but how can i achieve this ?
To make a field editable takes two parameters, this has been used to make the Date field editable. The first parameter instructs Glass.Mapper which field to make editable, the second parameter then specifies what the output should be when the page is not in page editing mode. This allows you to control the output of the field when in the two different modes.
Can anybody help me ?
For Experience editor mode, this works for me in razor view:
#Editable(model => model.SomeDateField, new { Format = "dd-MM-yyyy" })
Sitecore 8.2 though, with Glass 4.4.
What you want to do is to provide the default format but keep things the same for the main glass stuff. Like so:
foreach(var item in Model)
{
<div>#Editable(item, x => x.Start_Date, x=>x.Start_Date.ToString("MMMM dd,yyyy"))</div>
}
This will make the date a normal date when editing, but allow you to format it for the final page.
Usually in this case i use different code for "Normal View" and "Experience Editor", so for normal view you need only to display the date with format without making it editable, and on experience editor you need only to edit the date field the author will not care about the date format with experience editor, so your code will be like this :
foreach(var item in Model)
{
{
#if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
{
<div>#Editable(item, x => x.Start_Date)</div>
}
else
{
<div>#item.Start_Date.ToString("MMMM dd,yyyy")</div>
}
}
}
I have tried that as well but it is throwing an error like below
**Value cannot be null. Parameter name: objectToSwitchTo
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Common.Switcher2.Enter(TValue objectToSwitchTo)
at Glass.Mapper.Sc.GlassHtml.MakeEditable[T](Expression1 field, Expression1 standardOutput, T model, Object parameters, Context context, Database database, TextWriter writer)**
Any help on this ?

Sitecore how to show item's field in a datasource instead of item name

In a templateItem I have following information for a field.
Name : Product type
field type : 'Droplink'
DataSource : DataSource=/sitecore/content/Enumerations/Products/Product type/
When the content editor creates an item based on above template, for the field 'Product type' in the dropdown he will see the items under ../Product type. My question is for the items which are show in dropdown how to show some other field instead of item name
This functionality does not exist out of the box, although the code for the DropLink field looks like has code in there to be able to do this (take a look at the GetItemHeader() method in Sitecore.Shell.Applications.ContentEditor.LookupEx), I do not know how to utilize the parameter through the Content Editor though...
It's simple enough to create a custom field to achieve this though:
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Shell.Applications.ContentEditor;
namespace MyProject.Custom.Fields
{
public class CustomDropLink : LookupEx
{
protected override string GetItemHeader(Item item)
{
if (string.IsNullOrEmpty(this.FieldName))
this.FieldName = StringUtil.ExtractParameter("FieldName", this.Source).Trim();
return base.GetItemHeader(item);
}
}
}
Then register your custom class in the core database under /sitecore/system/Field types/. You can do this by duplicating /sitecore/system/Field types/Link Types/Droplink and setting the following values:
Assembly: MyProject.Custom
Class: MyProject.Custom.Fields.CustomDropLink
Control: <set this to empty>
Then when you utilise this field set the Source of your field like so:
Datasource=/sitecore/content/path/to/items&FieldName=Title

Drupal 8, get programmatically the list of fields of a custom content

I want create programmatically a custom content (custom content created via the admin UI). But, before the creation, I want check programmatically the types of fields of my custom content
My custom content contains a field "body" (type text), a field "description" (type text), an int field (type int), an attached file field (type fid ?)...
I test several ways with the new api of Drupal 8, my last try..
// I get the entity object "my_custom_content"
$entity_object = NodeType::load("my_custom_content");
dpm($entity_object); //Work perfectly
$test = \Drupal::getContainer()->get("entity_field.manager")->getFieldDefinitions("my_custom_content",$entity_object->bundle())
//The \Drupal::getConta... Return an error : The "my_custom_content" entity type does not exist.
With this $entity_object, how can I get the list of the fields of my custom content ?
I see the EntityFieldManager Class, the FieldItemList Class...But I still do not understand how to play with drupal 8 / class / poo ... :/
Thanks !
NodeType is the (config) bundle entity for the Node (content) entity.
The correct call would be:
\Drupal::service('entity_field.manager')->getFieldDefinitions('node', 'my_custom_content');
To get the field definitions of any entity_type use the following structure:
\Drupal::service('entity_field.manager')->getFieldDefinitions(ENTITY_TYPE_ID, BUNDLE_ID);
For example, if you want to get all the field definitions of a paragraph bundle with the id multy_purpose_link then replace ENTITY_TYPE_ID with paragraph and BUNDLE_ID with multy_purpose_link
\Drupal::service('entity_field.manager')->getFieldDefinitions('paragraph', 'multy_purpose_link');
The given answers are deprecated. You should now load the entity and just use getFieldDefinitions() to fetch the field definitions.
$node = Node::load($slide_id);
$field_defs = $node->getFieldDefinitions();
Or
$field_defs = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', '<taxonomy machine name here>');
If you want to get the list of field_definitions for a taxonomy vocabulary
If the entity type does not have a bundle, for example the user entity.
Try this:
// All user fields and ones added
$user_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('user','user');
// Just default
$default_user_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('user', NULL);

Sitecore|WFFM| Custom Error Message with details| on Same Page with Form

I have a Web Form for Marketer set up done for one of my Pages.
I have Custom Submit Action written for it as shown below in the code snippet -
public class **CustomFormSubmit : ISaveAction**
{
public void Execute(ID formid, AdaptedResultList fields, params object[] data)
{
try
{
**//var returnValue= Custom Logic to save form data // returns true or false**
}
catch (Exception ex)
{
Logger.Log(ex.Message + ":" + builder, ExceptionCategory.Error);
throw;
}
}
In my above Web form - Success Mode is - SuccessMode/Redirect and I have a success Page configured for it.
My requirement in above scenario is to keep user on the same Page(with Form) if returnValue is false . (as shown in above code snippet)
Can anyone Please guide me in the above scenario as - how to keep user on the same Page with values filled in the form so that user can submit it again.
Product Details - 7.2 rev. 141226 , Web Forms for Marketers 2.4 rev.140117
To add further details -
I am not sure how can I go back to my page instead of the redirection in case if return is false in the above code snippet.
As soon the submit button is clicked the above function- Execute- gets called.
How do I go back to the Page - Do I need to override any function or customize something.
If any exception comes while saving data- then the control goes back to the same Page with all values filled by user retained -with the Save Action Failed Message which is configured in Sitecore .
So my requirement will be to go to to the form as happening in case of Exception when false comes as return value while saving data and to put customised Error Messages which might change each time, so not statically configured ,rather a dynamic one.
Thanks!
Saurabh
One option will be to redirect to the original page with the Form on.
Enable your form to populate the fields via Query String using the ReadQueryString property, via Presentation Details of the Form Renderer:
So on false of your Save Action you create a collection of query strings with the name of each Field, as it appears in the Form, followed by the User's value.
The code below will loop through all your fields and arrange them into a QueryString with its FieldName and Value;
string urlOfForm = HttpContext.Current.Request.Url.AbsolutePath;
var queryString = new StringBuilder("?");
foreach (AdaptedControlResult field in fields)
{
queryString.Append(string.Format("{0}={1}&", field.FieldName, field.Value));
}
urlOfForm = urlOfForm + queryString;
HttpContext.Current.Response.Redirect(urlOfForm);
Sitecore will then automatically populate the appropriate fields with the values, achieving your requirement.
EDIT
I have found that most Exceptions thrown will take the user back to the Form with their values populated. You can then pass in the cause of the failure to write to your CRM. See below for Example
if (submitFailed)
{
throw new Exception("The email address entered already exists in our System");
}
The complexity then comes in dynamically swapping out the Save Action Failed Message to show this Exception Message. All posts I find about custom Save Action Message state the only real approach is to redirect via your Custom Save Action to a different page showing a different message. Which is not suitable to your requirements.
I have found the pipeline Args you are going to need to patch FormSubmitFailedArgs and SubmitFailedArgs. The Former will need the following change
public FormSubmitFailedArgs(ID formID, AdaptedResultList fields, ID actionFailed, Exception ex)
: base(formID, actionFailed, ex)
{
this.Fields = fields;
this.ErrorMessage = ex.Message;
}
and the Latter will need
public SubmitFailedArgs(ID formID, ID actionFailed, string errorMessage, Exception innerException)
{
this.FormID = formID;
this.ActionFailed = actionFailed;
this.ErrorMessage = innerException.Message;
this.InnerException = innerException;
}
Location and Styling of Submit Message:
You need to find the FormRender sublayout file, this is defaulted to website\sitecore modules\Web\Web Forms for Marketers\Control\SitecoreSimpleFormAscx.ascx inside there you will find a compont called SubmitSummary this renders out the submit message so move it to where you require.
Also note it references the CssClass scfSubmitSummary this is what you will need to target to change the styling of the Message. This Answer is already REALLY long so I won't give a blow by blow how to change the styling of that class, see here for example - http://www.awareweb.com/awareblog/10-1-13-wffmguide
Pipeline Patching
I've dug in deeper, in order to use the custom Args we created for using the exception error message you will need to control the Pipeline which ultimately uses those Args, this is the processor Sitecore.Form.Core.Pipelines.FormSubmit.FormatMessage, Sitecore.Forms.Core in the <errorSubmit> Pipeline.
From my investigation it shouldn't take much effort then its a matter of patching it, you can modify if the Sitecore.Forms.config directly or use patch:instead from a config file within the App_Config/Includes folder - see here for more info.
One option would be to create a Custom Form Verification Action. You could save the data here, although it would be better to verify the data against your API here and then save the data in custom save action, simply since this seems more logical as to how WFFM was meant to function.
using Sitecore.Data;
using Sitecore.Form.Core.Controls.Data;
using Sitecore.Form.Core.Submit;
using System;
using System.Collections.Generic;
namespace Custom.WFFM
{
public class CustomVerificationStep : BaseCheckAction
{
public string FailedMessage { get; set; }
public override void Execute(ID formid, IEnumerable<ControlResult> fields)
{
// Call your API
// You have access to the fields, so you can pass them through as parameters to your if needed
bool flag = ServiceAPI.ValidateUserData(param1, param2, etc);
if (!flag)
{
throw new Exception(string.Format(this.FailedMessage ?? "There was an error while verifying the data against the service call"));
}
}
public override ActionState QueryState(ActionContext context)
{
return ActionState.DisabledSingleCall;
}
}
}
Create the corresponding Verification Action under /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Form Verification:
You can change the error message by setting it in the Parameters field as <FailedMessage>Custom Failed Error Message</FailedMessage>.
And then add your verification step to your form:
If you need a different error message per form then you can set the error message to display from the Error Messages tab.
The user will then be returned to the same without any of the save actions being called and the form fields still filled in.