Vulnerability in EPiServer.Forms
Does anyone know how I can set the default name of a shared block? The standard way of overriding SetDefaultValues(ContentType contentType) in the class declaration does not work since blocks by default do not implement IContent. Does anyone have a solution for this?
SetDefaultValues is not part of IContent. It is definied on interface IInitializableContent which is implemented by ContentData (which BlockData inherits). So overriding of SetDefaultValues should be possible for blocks.
SetDefaultValues is a valid override for block classes, and works for other properties on them, but not on the block name.
You could have code as:
IContent blockAsContent = this as IContent;
if (blockAsContent != null)
//Shared block instance
blockAsContent.Name = "MyName";
I have tried to code it the way you are proposing Johan, but it doesnt work. I still get the popup asking me to specify a better name than "New Block" when I try to create the block.
If you want to change the "New Block" name that is set when creating blocks via the UI then you can change it by overriding that specific key in the language files. Since the default name is language specific, it is therefore stored in the language files ;)
<language name="English" id="en">
<newitemdefaultname>Please enter a name for this block</newitemdefaultname>
You can do the same for pages with a pagedata node or folders with a contentfolder
Ben, really magic strings here ;)
Would be nice to be able to set this through code though
Haha, well I guess it wasn't intended to be changed. Linus has blogged on the actual XML structure here http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/New-standardized-format-for-content-type-localizations/
It is the same structure for when you want to localize the name or description of a content type. But in this case we add the localizations to the base types; PageData, BlockData, ContentFolder.
What I meant was the newitemdefaultname element which I've not seen any documentation on :\
Setting newitemdefaultname doesnt seem to work correctly, when the block is created the name in the top left input field is still "new block", but when the user doesnt change the name, the value of newitemdefaultname is shown in the popup asking the user to change the name to something better than "new block". This means the editor still has to change the name. Any other solutions to this problem?
Consider that EPiServer can't know what the default name should be in the first step since you have not yet selected which content type you want to use.
As you say, the suggestion to name will be your provided default name unless the editor starts with editing the name.
Obviously i'm not expecting episerver to know the default name before a content type has been selected, but episerver should be able to know the default name after I have selected a type, since this works for pages right now (by overriding SetDefaultValues and setting PageName).
Just because EPiServer asks the editor to change the name to something better than "new block" (or in Ben's example "Please enter a name for this block"), it doesn't mean that the user must change name.
In my example I could use the following to work but EPiServer seems to have the resources cached for a while.
and the editor can select "Teasy tease" even if EPiServer says "Consider renaming the content to something more descriptive than default."
However I'm not able to set the PageName using SetDefaultValues. I'm testing in Alloy and 7.16. Which version are you running on?