Multisite Custom field
How do you add a custom field to the 'Create a site' page?
I want to add a custom field under 'Domain', the problem is we will have 10 hotel websites and each hotel has a unique ID. When someone creates a site I want to force them to enter the hotel ID but I can't seem to find any information on how to do this. I can find information on how to add it to the page as a property but I would prefer it as a site property.
Thanks
Hi Ben,
Thank you for contacting our support service.
There is no way you can add a property to the Site object the same way you do for a page. There is however a workaround to this restriction. It consists of having a setting in the Administration-.Settings Basic settings that will be persisted and unique for every site. I have attached a control that enables this functionality.
In order to get the control working you need to add it to your solution and build it. Also you need to register it in your Global.asax class as follows:
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized += Bootstrapper_Initialized;
void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
if
(e.CommandName ==
"Bootstrapped"
)
Telerik.Sitefinity.Services.SystemManager.RegisterBasicSettings<GenericBasicSettingsView<CustomContractSettingsView, CustomContract>>(
"Custom"
,
"Custom Settings"
,
null
,
true
);
In order to obtain the value for the current site context you can use the following query:
var = isSiteLanguageSpec = SystemManager.CurrentContext.GetSetting<CustomContract, CustomContract>().IsLanguageSpecific
I have also attached a video for further reference.
I hope this helps. Let me know if you have further questions.
Regards,
Ivan D. Dimitrov
Telerik
Hi Ivan,
Thank you for your help, however I do have a follow up question:
When I try to add a TextField to store hotelId, it shows on the settings page and I can enter information however it does not save the information. I have tried to add another ChoiceField as well with the same problem.
What am I missing?
Thank
Ben
Hi Ben,
As mentioned this is a sample control. If you want to add additional functionality to it you need to alter the code as well. You need to define the property you add in the CustomContract class, you need to declare it in the CustomContractSettingsView class. Adding the fields to the template alone is not sufficient for the field to persist.
Should you experience any difficulties in the process, feel free to send a support tickets where we can handle your particular case.
Regards,
Ivan D. Dimitrov
Telerik
Hi,
Is it possible to break the inheritance on the custom setting through programming? Every time we create a new site we have to manually break the inheritance before we can run our creation routine.
Thanks
Ben
Hi Ben,
That's a tough one. The problem is that Sitefinity does not throw an event when a site is created and so it is hard to reach a point to plug in code and do this.
You can however try using the ManagerExecuting event which is available for all managers in Sitefinity:
http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/what-event-is-raised-when-a-page-is-published-and-how-do-i-capture-it
Here is how you can modify it for Multisite:
void
Bootstrapper_Initialized(
object
sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
if
(e.CommandName ==
"Bootstrapped"
)
MultisiteManager.Executing +=
new
EventHandler<Telerik.Sitefinity.Data.ExecutingEventArgs>(MultisiteManager_Executing);
private
void
MultisiteManager_Executing(
object
sender, Telerik.Sitefinity.Data.ExecutingEventArgs e)
if
(e.CommandName ==
"CommitTransaction"
|| e.CommandName ==
"FlushTransaction"
)
var provider = sender
as
MultisiteDataProvider;
var dirtyItems = provider.GetDirtyItems();
if
(dirtyItems.Count != 0)
foreach
(var item
in
dirtyItems)
//Can be New, Updated, or Deleted
SecurityConstants.TransactionActionType itemStatus = provider.GetDirtyItemStatus(item);
var site = item
as
Site;
if
(site !=
null
)
if
(itemStatus == SecurityConstants.TransactionActionType.New)
//Break the inheritance here
I would advise caution using the Manager_Executing event on managers in Sitefinity since it is thrown for all operations with managers. This can cause performance impact if many operations are made.
Additionally you can see sample API calls on how to break permission inheritance below:
http://www.sitefinity.com/blogs/boyan-barnevs-blog-/2013/06/19/working-with-sitefinity-permissions-api---managing-permissions
I hope this helps and please let me know if you have any additional questions.
Regards,