Commit 98fb82e6 authored by Viet Hoang's avatar Viet Hoang

Merge branch 'media-public-url-picker' into 'develop'

Media public url picker

See merge request !10
parents 02c81be0 1d1650df
For more information, please visit the blogs:
* [Content Audit Tool](https://buoctrenmay.wordpress.com/2017/02/19/content-audit-tool/)
* [Image Coordinate Picker - Custom Field](https://buoctrenmay.wordpress.com/2017/03/10/sitecore-custom-field-image-coordinate-picker/)
\ No newline at end of file
* [Image Coordinate Picker - Custom Field](https://buoctrenmay.wordpress.com/2017/03/10/sitecore-custom-field-image-coordinate-picker/)
* [Sync Media Folder Sitecore Processor](https://buoctrenmay.wordpress.com/2017/03/25/storing-sitecore-media-assets-on-the-file-system-and-how-to-get-synced-at-your-machine/)
* [Media Provider For Graysale](https://buoctrenmay.wordpress.com/2017/05/24/how-to-enable-grayscale-feature-on-sitecore-xp-8/)
* [Pre-population Item Version](https://buoctrenmay.wordpress.com/2017/05/27/pre-population-item-version-module-for-sitecore-development/)
......@@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Vhs.MediaProviderForGrayscale")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyCopyright("Copyright © viet.hoang.sitecore@gmail.com 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<controlSources>
<source mode="on" namespace="Vhs.MediaPublicUrlPickerField.Fields"
assembly="Vhs.MediaPublicUrlPickerField" prefix="vhs" />
</controlSources>
<settings>
<setting name="Vhs.MediaPublicUrlPickerField.DialogWidth" value="800"/>
<setting name="Vhs.MediaPublicUrlPickerField.DialogHeight" value="150"/>
<setting name="Vhs.MediaPublicUrlPickerField.DomainFieldName" value="PublicDomain|MainDomain"/>
<setting name="Vhs.MediaPublicUrlPickerField.DefaultPublicDomain" value="http://viethoang.local"/>
</settings>
</sitecore>
</configuration>
\ No newline at end of file
namespace Vhs.MediaPublicUrlPickerField.Constants
{
public static class QueryStringKeys
{
public const string Value = "value";
public const string ContainerId = "containerId";
public const string Code = "code";
public const string View = "view";
}
}
\ No newline at end of file
using System;
using SC = Sitecore;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Resources.Media;
using Sitecore.Web;
using Sitecore.Web.UI.Pages;
using Vhs.MediaPublicUrlPickerField.Constants;
using Vhs.MediaPublicUrlPickerField.Services;
namespace Vhs.MediaPublicUrlPickerField.Dialogs
{
public class MediaPublicUrlPickerDialog : DialogForm
{
private const string Separator = "|";
private readonly Database _masterDb = Factory.GetDatabase("master");
public SC.Web.UI.HtmlControls.Image ImageFrame;
public SC.Web.UI.HtmlControls.Edit TextBoxPublicUrl;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (TextBoxPublicUrl == null) return;
var containerId = WebUtil.GetQueryString(QueryStringKeys.ContainerId);
var currentItem = _masterDb.Items.GetItem(containerId);
if (currentItem == null) return;
var medialUrl = MediaManager.GetMediaUrl(_masterDb.Items.GetItem(currentItem.ID));
var itemHasDomain = currentItem.Parent;
var domainCandidate = string.Empty;
while (itemHasDomain != null)
{
var domainFieldNames = ConfigurationService.DomainFieldName.Split(new[] { Separator },
StringSplitOptions.RemoveEmptyEntries);
foreach (var domainFieldName in domainFieldNames)
{
domainCandidate = itemHasDomain.Fields[domainFieldName] != null
? itemHasDomain.Fields[domainFieldName].Value
: string.Empty;
if (!string.IsNullOrWhiteSpace(domainCandidate)) break;
}
if (string.IsNullOrWhiteSpace(domainCandidate)) itemHasDomain = itemHasDomain.Parent;
else break;
}
var publicDomain = !string.IsNullOrWhiteSpace(domainCandidate)
? domainCandidate
: ConfigurationService.DefaultPublicDomain;
TextBoxPublicUrl.Value = medialUrl.Replace("/sitecore/shell/",
SC.StringUtil.EnsurePostfix('/', publicDomain));
}
}
}
\ No newline at end of file
using System.Collections.Specialized;
using Sitecore.Shell.Applications.ContentEditor;
using Sitecore.Web.UI.Sheer;
using Vhs.MediaPublicUrlPickerField.Constants;
using Vhs.MediaPublicUrlPickerField.Services;
using SC = Sitecore;
namespace Vhs.MediaPublicUrlPickerField.Fields
{
public class MediaPublicUrlPickerField : Custom, IContentField
{
public string GetValue()
{
return this.Value;
}
public void SetValue(string value)
{
this.Value = value;
}
public override void HandleMessage(Message message)
{
base.HandleMessage(message);
if (!message.Name.Equals("vhs:GetPublicUrl"))
return;
// manage to get the container id (Sitecore item id) of this field
// onFocus attribute's value will be like this
// javascript:return scContent.activate(this,event,'sitecore://master/{6DB97A83-480E-4F51-A9D5-B6C688C651B3}?lang=en&ver=1&fld={AA29FFC7-DEA0-4053-87A3-967C198AB652}&ctl=FIELD313682656')
// in this case, container id = 6DB97A83-480E-4F51-A9D5-B6C688C651B3
var onFocus = this.Attributes["onfocus"];
var containerId = onFocus.Split('?')[0].Split('{')[1].Replace("}", string.Empty);
SC.Context.ClientPage.Start(
this,
"GetPublicUrl",
new NameValueCollection { { QueryStringKeys.ContainerId, containerId } });
}
protected void GetPublicUrl(ClientPipelineArgs args)
{
if (args.IsPostBack)
{
if (args.HasResult && args.Result != this.Value)
{
this.SetModified();
this.SetValue(args.Result);
}
}
else
{
var uri = string.Format(
"{0}&{1}={2}&{3}={4}",
SC.UIUtil.GetUri("control:MediaPublicUrlPickerDialog"),
QueryStringKeys.Value,
this.GetValue(),
QueryStringKeys.ContainerId,
args.Parameters[QueryStringKeys.ContainerId]);
SheerResponse.ShowModalDialog(uri, ConfigurationService.DialogWidth, ConfigurationService.DialogHeight,
string.Empty, true);
args.WaitForPostBack();
}
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Vhs.MediaPublicUrlPickerField")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Vhs.MediaPublicUrlPickerField")]
[assembly: AssemblyCopyright("Copyright © viet.hoang.sitecore@gmail.com 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2B410063-2D95-4177-A3D0-1437358DD400")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using SC = Sitecore;
namespace Vhs.MediaPublicUrlPickerField.Services
{
public static class ConfigurationService
{
public static string DialogWidth
=> SC.Configuration.Settings.GetSetting("Vhs.MediaPublicUrlPickerField.DialogWidth", "800");
public static string DialogHeight
=> SC.Configuration.Settings.GetSetting("Vhs.MediaPublicUrlPickerField.DialogHeight", "150");
public static string DomainFieldName
=>
SC.Configuration.Settings.GetSetting("Vhs.MediaPublicUrlPickerField.DomainFieldName",
string.Empty);
public static string DefaultPublicDomain
=>
SC.Configuration.Settings.GetSetting("Vhs.MediaPublicUrlPickerField.DefaultPublicDomain",
string.Empty);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{74E54048-8F7F-4599-AB06-FB729CDAFCAA}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Vhs.MediaPublicUrlPickerField</RootNamespace>
<AssemblyName>Vhs.MediaPublicUrlPickerField</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Sitecore.Kernel, Version=10.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Sitecore.Kernel.NoReferences.8.2.170407\lib\NET452\Sitecore.Kernel.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\z.Vhs.MediaPublicUrlPickerField.config">
<SubType>Designer</SubType>
</Content>
<None Include="packages.config" />
<None Include="Properties\PublishProfiles\Local.pubxml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Web.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Constants\QueryStringKeys.cs" />
<Compile Include="Dialogs\MediaPublicUrlPickerDialog.cs" />
<Compile Include="Fields\MediaPublicUrlPickerField.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\ConfigurationService.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="sitecore modules\Shell\Vhs Apps\MediaPublicUrlPickerField\MediaPublicUrlPickerDialog.xml">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>11655</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:11655/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6"/>
<httpRuntime targetFramework="4.6"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers>
</system.codedom>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net46" developmentDependency="true" />
<package id="Sitecore.Kernel.NoReferences" version="8.2.170407" targetFramework="net46" developmentDependency="true" />
</packages>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense">
<MediaPublicUrlPickerDialog>
<FormDialog ID="Dialog" Icon="Network/32x32/environment_view.png" Header="Media Public URL Picker" OkButton="Close" CancelButton="false"
Text="Please press Ctrl + A then Ctrl + C to copy the public URL inside the texbox below.">
<!--Define Code Beside-->
<CodeBeside Type="Vhs.MediaPublicUrlPickerField.Dialogs.MediaPublicUrlPickerDialog, Vhs.MediaPublicUrlPickerField"/>
<Groupbox Header="Media Public URL (Please press Ctrl + A then Ctrl + C to copy it inside the texbox below)" Style="height:50px;">
<table width="100%">
<tr valign="center">
<td width="70%">
<div class="form-element">
<Edit ID="TextBoxPublicUrl" ReadOnly="false" Width="100%" MaxLength="200"/>
</div>
</td>
</tr>
</table>
</Groupbox>
</FormDialog>
</MediaPublicUrlPickerDialog>
</control>
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Vhs.PrePopulationItemVersion.SiteList"
value="site0|site1:zh-HK|site2:vi-VN"/>
<setting name="Vhs.PrePopulationItemVersion.DefaultSourceLanguage"
value="en" />
</settings>
<events>
<event name="item:versionAdded">
<handler type="Vhs.PrePopulationItemVersion.Events.ItemVersionAdded.PrePopulateItemVersionHandler, Vhs.PrePopulationItemVersion"
method="PrePopulateItemVersion" />
</event>
</events>
</sitecore>
</configuration>
\ No newline at end of file
using System;
using System.Linq;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Events;
using Sitecore.Globalization;
using Sitecore.StringExtensions;
using Vhs.PrePopulationItemVersion.Services;
namespace Vhs.PrePopulationItemVersion.Events.ItemVersionAdded
{
public class PrePopulateItemVersionHandler
{
public void PrePopulateItemVersion(object sender, EventArgs args)
{
var currentItem = Event.ExtractParameter(args, 0) as Item;
if (currentItem == null)
{
return;
}
var itemSiteInfo =
Sitecore.Configuration.Factory.GetSiteInfoList()?
.FirstOrDefault(
x =>
!x.RootPath.IsNullOrEmpty() && !x.StartItem.IsNullOrEmpty() &&
!x.RootPath.Equals(Sitecore.Constants.ContentPath, StringComparison.OrdinalIgnoreCase) &&
currentItem.Paths.FullPath.StartsWith(x.RootPath, StringComparison.OrdinalIgnoreCase));
if (itemSiteInfo == null)
{
return;
}
const string pipeSeparator = "|";
const string colonSeparator = ":";
var siteList = ConfigurationService.SiteList.Split(new[] { pipeSeparator },
StringSplitOptions.RemoveEmptyEntries);
var isAbleToPrePopulate = false;
var defaultSourceLanguage = ConfigurationService.DefaultSourceLanguage;
foreach (var site in siteList)
{
var segments = site.Split(new[] { colonSeparator }, StringSplitOptions.RemoveEmptyEntries);
var siteName = segments[0];
if (itemSiteInfo.Name.Equals(siteName, StringComparison.OrdinalIgnoreCase))
{
isAbleToPrePopulate = true;
defaultSourceLanguage = segments.Length > 1 ? segments[1] : defaultSourceLanguage;
break;
}
}
if (!isAbleToPrePopulate)
{
return;
}
Language sourceLanguage;
Language.TryParse(defaultSourceLanguage, out sourceLanguage);
if (sourceLanguage == null)
{
return;
}
var currentDatabase = Sitecore.Context.ContentDatabase;
if (currentDatabase == null)
{
return;
}
var prototypeItem = currentDatabase.GetItem(currentItem.ID, sourceLanguage).Versions.GetLatestVersion();
if (prototypeItem == null)
{
Log.Error(
string.Format("Error in {0}: {1} version of {2} is NOT existent.",
typeof (PrePopulateItemVersionHandler).FullName, itemSiteInfo.Language,
currentItem.Paths.FullPath), this);
return;
}
prototypeItem.Fields.ReadAll();
using (new EditContext(currentItem))
{
foreach (Sitecore.Data.Fields.Field field in prototypeItem.Fields)
{
if (!field.Shared && !field.Name.StartsWith("__") && !field.Value.IsNullOrEmpty())
{
currentItem.Fields[field.ID].SetValue(field.Value, force: true);
}
}
}
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Vhs.PrePopulationItemVersion")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Vhs.PrePopulationItemVersion")]
[assembly: AssemblyCopyright("Copyright © viet.hoang.sitecore@gmail.com 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ae2c750d-ce50-47dd-9900-1a53351c0b38")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using SC = Sitecore;
namespace Vhs.PrePopulationItemVersion.Services
{
public static class ConfigurationService
{
public static string SiteList
=>
SC.Configuration.Settings.GetSetting(
"Vhs.PrePopulationItemVersion.SiteList",
string.Empty);
public static string DefaultSourceLanguage
=>
SC.Configuration.Settings.GetSetting("Vhs.PrePopulationItemVersion.DefaultSourceLanguage",
"en");
}
}
\ No newline at end of file