public void Process(GetRenderingDatasourceArgs args) { Assert.ArgumentNotNull(args, nameof(args)); CheckboxField datasource = args.RenderingItem.Fields[Templates.RenderingOptions.Fields.SupportsLocalDatasource]; if (datasource == null || !datasource.Checked) { return; } var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); if (contextItem == null) { return; } var localDatasourceFolder = GetConfiguredLocalDatasourceFolder(contextItem, args.Prototype); if (localDatasourceFolder == null) { Log.Warn($"Cannot find the local datasource folder template '{Settings.LocalDatasourceFolderTemplate}'", this); return; } //Add the datasource folder to the top of the list to make it appear first in the dialog args.DatasourceRoots.Insert(0, localDatasourceFolder); }
public void Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem, [Content] DbTemplate template) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = contextItem.Paths.FullPath }; //act using (new SettingsSwitcher("Foundation.LocalDatasource.LocalDatasourceFolderTemplate", template.ID.ToString())) { processor.Process(getRenderingDatasourceArgs); } //assert var datasourceFolder = contextItem.GetChildren().First(); getRenderingDatasourceArgs.DatasourceRoots.First().ID.Should().Be(datasourceFolder.ID); datasourceFolder.TemplateID.Should().Be(template.ID); }
public void Process_LocalDatasourceNotExist_ShouldCreateDatasourceRoot(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem, [Content] DbTemplate template) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = contextItem.Paths.FullPath }; //act using (new SettingsSwitcher("Foundation.LocalDatasource.LocalDatasourceFolderTemplate", template.ID.ToString())) { processor.Process(getRenderingDatasourceArgs); } //assert var datasourceFolder = contextItem.GetChildren().First(); getRenderingDatasourceArgs.DatasourceRoots.First().ID.Should().Be(datasourceFolder.ID); datasourceFolder.TemplateID.Should().Be(template.ID); }
protected virtual void ResolveDatasource(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var source = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(source); if (string.IsNullOrEmpty(name)) { return; } var datasources = new Item[] {}; var provider = providerFactory.GetProvider(args.ContentDatabase); if (provider != null) { datasources = provider.GetDatasources(name, contextItem); } if (!datasources.Any()) { provider = providerFactory.GetFallbackProvider(args.ContentDatabase); if (provider == null) { return; } datasources = provider.GetDatasources(name, contextItem); } args.DatasourceRoots.AddRange(datasources); }
public void Process_SiteSettingIsNotSet_SourcesAndTemplateAreNotSet([Frozen]DatasourceProviderFactory factory, GetDatasourceLocationAndTemplateFromSite processor, Item renderingItem) { var args = new GetRenderingDatasourceArgs(renderingItem); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
protected virtual void ResolveDatasource(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var source = args.RenderingItem["Datasource Location"]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(source); if (string.IsNullOrEmpty(name)) { return; } var datasources = new Item[] {}; var provider = providerFactory.GetProvider(args.ContentDatabase); if (provider != null) { datasources = provider.GetDatasources(name, contextItem); } if (!datasources.Any()) { provider = providerFactory.GetFallbackProvider(args.ContentDatabase); if (provider == null) { return; } datasources = provider.GetDatasources(name, contextItem); } args.DatasourceRoots.AddRange(datasources); }
public void Process(GetRenderingDatasourceArgs args) { Assert.ArgumentNotNull(args, nameof(args)); CheckboxField datasource = args.RenderingItem.Fields[Templates.RenderingOptions.Fields.SupportsLocalDatasource]; if (datasource == null || !datasource.Checked) { return; } var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); if (contextItem == null) { return; } var localDatasourceFolder = this.GetConfiguredLocalDatasourceFolder(contextItem, args.Prototype); if (localDatasourceFolder == null) { Log.Warn($"Cannot find the local datasource folder template '{Settings.LocalDatasourceFolderTemplate}'", this); return; } //Add the datasource folder to the top of the list to make it appear first in the dialog args.DatasourceRoots.Insert(0, localDatasourceFolder); }
public void Process(GetRenderingDatasourceArgs args) { var db = args.Prototype == null ? args.ContentDatabase : args.Prototype.Database; using (new TraceOperation($"Add derived templates for selection in {(args.RenderingItem == null ? "rendering" : args.RenderingItem.Name)} rendering datasource dialog.")) { var index = 0; while (index < args.TemplatesForSelection.Count) { var template = args.TemplatesForSelection[index]; var allDerived = db.SelectItems("/sitecore/templates//*[contains(@#__Base template#, '" + template.ID + "')]"); foreach (var newTemplate in allDerived.Select(TemplateManager.GetTemplate)) { if (!args.TemplatesForSelection.Contains(newTemplate)) { args.TemplatesForSelection.Add(newTemplate); } } index++; } } }
protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasourceLocation = args.RenderingItem["Datasource Location"]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation); if (string.IsNullOrEmpty(name)) { return; } Item datasourceTemplate = null; var provider = providerFactory.GetProvider(args.ContentDatabase); if (provider != null) { datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem); } if (datasourceTemplate == null) { provider = providerFactory.GetFallbackProvider(args.ContentDatabase); if (provider != null) { datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem); } } args.Prototype = datasourceTemplate; }
public void Process(GetRenderingDatasourceArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } var locations = args.RenderingItem["Datasource Location"].Split('|'); if (!locations.Any(x => x.Contains(RelativePath))) { return; } args.DatasourceRoots.Clear(); foreach (var datasourceLocation in locations) { if (string.IsNullOrEmpty(datasourceLocation)) { continue; } if (datasourceLocation.StartsWith(RelativePath, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(args.ContextItemPath)) { CreateDatasource(args, datasourceLocation); } else { args.DatasourceRoots.Add(args.ContentDatabase.GetItem(datasourceLocation)); } } }
protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasourceLocation = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation); if (string.IsNullOrEmpty(name)) { return; } Item datasourceTemplate = null; var provider = providerFactory.GetProvider(args.ContentDatabase); if (provider != null) { datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem); } if (datasourceTemplate == null) { provider = providerFactory.GetFallbackProvider(args.ContentDatabase); if (provider != null) { datasourceTemplate = provider.GetDatasourceTemplate(name, contextItem); } } args.Prototype = datasourceTemplate; }
public GetRenderingDatasourceRuleContext(GetRenderingDatasourceArgs args) : base(args.RenderingItem.ID) { Settings = new RulesSettings(); Args = args; Item = args.RenderingItem; }
public void Process_SiteSettingIsNotSet_SourcesAndTemplateAreNotSet([Frozen] DatasourceProviderFactory factory, GetDatasourceLocationAndTemplateFromSite processor, Item renderingItem) { var args = new GetRenderingDatasourceArgs(renderingItem); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
public void Process_SupportsLocalDatasourceFieldNotSet_ShouldReturnEmptyRoots(GetLocalDatasourceLocation processor, Db db, [Content] Item renderingItem) { var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem); //act processor.Process(getRenderingDatasourceArgs); //assert getRenderingDatasourceArgs.DatasourceRoots.Should().BeEmpty(); }
private void SetDatasourceRoots(GetRenderingDatasourceArgs args) { using (new TraceOperation("Run GetDatasourceLocation rules")) { _rulesRunner.RunGlobalRules(RulesFolders.Get_Rendering_Datasource, args.RenderingItem.Database, new GetRenderingDatasourceRuleContext(args)); } }
//public void Process(GetRenderingDatasourceArgs args) //{ // foreach (var location in // new ListString(args.RenderingItem["Datasource Location"])) // { // if (location.StartsWith("query:")) // { // Item contextItem = args.ContentDatabase.Items[args.ContextItemPath]; // if (contextItem != null) // { // string query = location.Substring("query:".Length); // IList<Item> queryItems = contextItem.Axes.SelectItems(query); // Item queryItem = contextItem.Axes.SelectSingleItem(query); // if (queryItem != null) // { // args.DatasourceRoots.Add(queryItem); // } // } // } // } //} public void Process(GetRenderingDatasourceArgs args) { Assert.IsNotNull(args, "args"); DatasourceLocation = args.RenderingItem["Datasource Location"]; if (QueryInDataSourceLocation()) { ProcessQuery(args); } }
public void Process_SiteSettingNameHasWrongFirmat_SourcesAndTemplateAreNotSet(GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName) { renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{settingName}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
public void Process_DatasourceProvidersAreNull_SourcesAndTemplateAreNotSet([Frozen]DatasourceProviderFactory factory, GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName) { var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { {"en", $"site:{setting}"} }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
private void ProcessQuery(GetRenderingDatasourceArgs args) { ContextItemPath = args.ContextItemPath; ContentDataBase = args.ContentDatabase; Item datasourceLocation = ResolveDatasourceRootFromQuery(); if (datasourceLocation != null) { args.DatasourceRoots.Add(datasourceLocation); } }
protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasourceLocation = args.RenderingItem[Templates.RenderingOptions.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation); if (string.IsNullOrEmpty(name)) { return; } args.Prototype = this.provider.GetDatasourceTemplate(contextItem, name); }
public void LaunchDmsPollWizard(GetRenderingDatasourceArgs args) { if (((args != null) && (args.RenderingItem != null)) && (args.RenderingItem.ID.ToString() == PollConstants.PollRenderingID)) { Item item = args.ContentDatabase.Items.GetItem(args.ContextItemPath); if (item != null) { string str = string.Format("/sitecore/shell/default.aspx?xmlcontrol=DMSPollWizard&id={0}&language={1}&showpageeditorfunctionality=False", item.ID, item.Language.Name); args.DialogUrl = str; } } }
public void Process(GetRenderingDatasourceArgs args) { Assert.IsNotNull(args, "args"); string sources = args.RenderingItem["Datasource Location"]; if (IsScripted(sources)) { var items = new ItemList(); Item contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); GetScriptedQueries(sources, contextItem, items); args.DatasourceRoots.AddRange(items); } }
protected virtual void ResolveDatasourceTemplate(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasourceLocation = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(datasourceLocation); if (string.IsNullOrEmpty(name)) { return; } args.Prototype = this.provider.GetDatasourceTemplate(contextItem, name); }
public void Process(GetRenderingDatasourceArgs args) { Assert.ArgumentNotNull(args, nameof(args)); var datasource = args.RenderingItem[DatasourceLocationFieldName]; if (!DatasourceConfigurationService.IsSiteDatasourceLocation(datasource)) { return; } ResolveDatasource(args); ResolveDatasourceTemplate(args); }
public void Process(GetRenderingDatasourceArgs args) { Assert.IsNotNull(args, "args"); var sources = args.RenderingItem["Datasource Location"]; if (IsScripted(sources)) { var items = new ItemList(); var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); GetScriptedQueries(sources, contextItem, items); args.DatasourceRoots.AddRange(items); } }
public void Process_SiteSettingNameHasWrongFirmat_SourcesAndTemplateAreNotSet([Frozen] DatasourceProviderFactory factory, GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName) { renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{settingName}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
public void Process(GetRenderingDatasourceArgs args) { Assert.ArgumentNotNull(args, nameof(args)); var datasource = args.RenderingItem[Templates.DatasourceConfiguration.Fields.DatasourceLocation]; if (!DatasourceConfigurationService.IsSiteDatasourceLocation(datasource)) { return; } ResolveDatasource(args); ResolveDatasourceTemplate(args); }
public void Process(GetRenderingDatasourceArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (!string.IsNullOrEmpty(args.CurrentDatasource)) { return; } var locations = args.RenderingItem["Datasource Location"].Split('|'); if (!locations.Any(x => x.StartsWith(RelativePath, StringComparison.OrdinalIgnoreCase))) { return; } args.DatasourceRoots.Clear(); foreach (var datasourceLocation in locations) { if (string.IsNullOrEmpty(datasourceLocation)) { continue; } if (datasourceLocation.StartsWith(RelativePath, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(args.ContextItemPath)) { CreateDatasource(args, datasourceLocation); } else if (datasourceLocation.StartsWith(QueryPrefix, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(args.ContextItemPath)) { var query = datasourceLocation.Substring(QueryPrefix.Length); AddRootsFromQuery(args, query); } else { var datasourceLocationItem = args.ContentDatabase.GetItem(datasourceLocation); if (datasourceLocationItem == null) { throw new ArgumentException(FormattableString.Invariant($"Could not find Datasource Root at the given location: {datasourceLocation}")); } args.DatasourceRoots.Add(datasourceLocationItem); } } }
protected virtual void ResolveDatasource(GetRenderingDatasourceArgs args) { var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var source = args.RenderingItem[Templates.RenderingOptions.Fields.DatasourceLocation]; var name = DatasourceConfigurationService.GetSiteDatasourceConfigurationName(source); if (string.IsNullOrEmpty(name)) { return; } var datasourceLocations = this.provider.GetDatasourceLocations(contextItem, name); args.DatasourceRoots.AddRange(datasourceLocations); }
private GetRenderingDatasourceArgs CreatePipelineArgs(Item renderingItem, Item contextItem) { GetRenderingDatasourceArgs renderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { FallbackDatasourceRoots = new List <Item>() { context.ContentDatabase.GetRootItem() }, ContentLanguage = contextItem.Language, ContextItemPath = contextItem != null ? contextItem.Paths.FullPath : string.Empty, ShowDialogIfDatasourceSetOnRenderingItem = true }; return(renderingDatasourceArgs); }
private void ResolveDatasourceTemplate(Rendering rendering) { var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(rendering.RenderingItem.InnerItem) { FallbackDatasourceRoots = new List<Item> { Context.Database.GetRootItem() }, ContentLanguage = rendering.Item?.Language, ContextItemPath = rendering.Item?.Paths.FullPath ?? PageItem.Paths.FullPath }; CorePipeline.Run("getRenderingDatasource", getRenderingDatasourceArgs); DatasourceTemplate = getRenderingDatasourceArgs.Prototype; }
public void Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet(IDatasourceProvider sourceProvider, [Substitute]DatasourceProviderFactory factory, DbItem renderingItem, Db db, string settingName, Item[] sources, Item sourceTemplate) { var processor = new GetDatasourceLocationAndTemplateFromSite(factory); sourceProvider.GetDatasources(Arg.Any<string>(), Arg.Any<Item>()).Returns(sources); sourceProvider.GetDatasourceTemplate(Arg.Any<string>(), Arg.Any<Item>()).Returns(sourceTemplate); factory.GetProvider(Arg.Any<Database>()).Returns(sourceProvider); var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Should().Contain(sources); args.Prototype.Should().Be(sourceTemplate); }
private void ResolveDatasourceTemplate(Rendering rendering) { var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(rendering.RenderingItem.InnerItem) { FallbackDatasourceRoots = new List <Item> { Context.Database.GetRootItem() }, ContentLanguage = rendering.Item?.Language, ContextItemPath = rendering.Item?.Paths.FullPath ?? this.PageItem.Paths.FullPath }; this.CorePipeline.Run("getRenderingDatasource", getRenderingDatasourceArgs); this.DatasourceTemplate = getRenderingDatasourceArgs.Prototype; }
public void Process_DatasourceProvidersAreNull_SourcesAndTemplateAreNotSet([Frozen] DatasourceProvider provider, GetDatasourceLocationAndTemplateFromSite processor, DbItem renderingItem, Db db, string settingName) { var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Count.Should().Be(0); args.Prototype.Should().BeNull(); }
private static Item AddDatasourceItem(GetRenderingDatasourceArgs args, Item datasourceFolder) { var datasourceTemplate = args.RenderingItem["Datasource Template"]; var datasourceTemplateItem = (TemplateItem)args.ContentDatabase.GetItem(datasourceTemplate); var count = datasourceFolder.Children.Count(c => c.TemplateID.Equals(datasourceTemplateItem.ID)); using (new SecurityDisabler()) { using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system"))) { using (new LanguageSwitcher(args.ContentLanguage)) { return(datasourceFolder.Add(FormattableString.Invariant($"{datasourceTemplateItem.Name} {count + 1}"), datasourceTemplateItem)); } } } }
public void RemovesDatasourceRoot() { var newTemplateId = ID.NewID; var componentsFolderTemplateId = ID.Parse("{122AE27A-D84F-4C5E-8367-0F42C764976E}"); var dsFolderId = ID.NewID; using (var db = new Db() { new DbTemplate("ComponentsFolder", componentsFolderTemplateId), new DbTemplate("PageTemplate", newTemplateId), new DbTemplate("WebsiteFolder", TemplateIDs.WebsiteFolder), new DbItem("Website", ID.NewID, TemplateIDs.WebsiteFolder) { new DbItem("home"), new DbItem("_components", ID.NewID, componentsFolderTemplateId) { new DbItem("PageTemplate", dsFolderId, componentsFolderTemplateId) } }, new DbItem("rendering") { new DbField("Datasource template") { Value = newTemplateId.ToString() } } }) { var home = db.GetItem("/sitecore/content/Website/home"); var rendering = db.GetItem("/sitecore/content/rendering"); var args = new GetRenderingDatasourceArgs(rendering) { ContextItemPath = home.Paths.FullPath }; args.DatasourceRoots.Add(db.GetItem(dsFolderId)); var ctx = new GetRenderingDatasourceRuleContext(args); var action = new RemoveWebsiteDatasourceRootAction <GetRenderingDatasourceRuleContext>(); ctx.Args.DatasourceRoots.Should().HaveCount(1); action.Apply(ctx); ctx.Args.DatasourceRoots.Should().HaveCount(0); } }
public void Process(GetRenderingDatasourceArgs args) { string dataSourceLocation = args.RenderingItem.Fields[DataSourceLocationField].Value; if (string.IsNullOrWhiteSpace(dataSourceLocation)) { return; } if (!dataSourceLocation.StartsWith(RelativePath)) { return; } if (string.IsNullOrWhiteSpace(args.ContextItemPath)) { return; } string subFolderPath = args.ContextItemPath + dataSourceLocation.Substring(1); if (args.ContentDatabase.GetItem(subFolderPath) != null) { return; } Item parent = args.ContentDatabase.GetItem(args.ContextItemPath); if (parent == null) { return; } string newItemName = dataSourceLocation.Substring(2); string[] foldersToCreate = newItemName.Split('/'); foreach (var substring in foldersToCreate) { using (new SecurityDisabler()) { Client.Site.Notifications.Disabled = true; parent = parent.Add(substring, FolderTemplate); Client.Site.Notifications.Disabled = false; } } }
private static Item AddDatasourceItem(GetRenderingDatasourceArgs args, Item datasourceFolder) { string datasourceTemplate = args.RenderingItem["Datasource Template"]; Item item = args.ContentDatabase.GetItem(datasourceTemplate); string datasourceName = CreateDatasourceName(datasourceFolder, item); using (new SecurityDisabler()) { using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system"))) { using (new LanguageSwitcher(args.ContentLanguage)) { Item datasourceItem; if (item.TemplateID == TemplateIDs.Template) { datasourceItem = datasourceFolder.Add(datasourceName, (TemplateItem)item); } else if (item.TemplateID == TemplateIDs.BranchTemplate) { datasourceItem = datasourceFolder.Add(datasourceName, (BranchItem)item); } else { throw new ArgumentException(FormattableString.Invariant($"Datasource Template \"{datasourceTemplate}\" does not correspond to a valid template or branch template.")); } Item localizedDatasource = datasourceItem.Database.GetItem(datasourceItem.ID, args.ContentLanguage); if (localizedDatasource.Versions.Count == 0) { using (new EditContext(localizedDatasource)) { localizedDatasource.Versions.AddVersion(); } } return(localizedDatasource); } } } }
public void Process(GetRenderingDatasourceArgs args) { Assert.ArgumentNotNull(args, nameof(args)); Assert.IsNotNull(_providers, typeof(IDatasourceProvider)); var source = args.RenderingItem[DatasourceLocationFieldName]; foreach (var datasourceProvider in _providers) { if (!datasourceProvider.CanAct(source)) { continue; // current provider cannot act on this data source } var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); var datasources = datasourceProvider.GetDatasources(source, contextItem); args.DatasourceRoots.AddRange(datasources); } }
public virtual void Process(GetRenderingDatasourceArgs args) { Assert.IsNotNull(args, "args"); RenderingItem rendering = new RenderingItem(args.RenderingItem); UrlString urlString = new UrlString(rendering.Parameters); var contentFolder = urlString.Parameters[TEMPLATE_PARAMETER]; if (string.IsNullOrEmpty(contentFolder)) { return; } if (!ID.IsID(contentFolder)) { Log.Warn(string.Format("{0} for Rendering {1} contains improperly formatted ID: {2}", TEMPLATE_PARAMETER, args.RenderingItem.Name, contentFolder), this); return; } string text = args.RenderingItem["Datasource Location"]; if (!string.IsNullOrEmpty(text)) { if (text.StartsWith("./") && !string.IsNullOrEmpty(args.ContextItemPath)) { var itemPath = args.ContextItemPath + text.Remove(0, 1); var item = args.ContentDatabase.GetItem(itemPath); var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); if (item == null && contextItem != null) { string itemName = text.Remove(0, 2); //if we create an item in the current site context, the WebEditRibbonForm will see an ItemSaved event and think it needs to reload the page using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system"))) { var datasourceLocationitem = contextItem.Add(itemName, new TemplateID(ID.Parse(contentFolder))); // Set the sort order for the datasource location to 0 so it sorts to the top. using (new EditContext(datasourceLocationitem)) { datasourceLocationitem.Fields["__Sortorder"].Value = "0"; } } } } } }
public void Process(GetRenderingDatasourceArgs args) { foreach (var dataSourceLocation in new ListString(args.RenderingItem["Datasource Location"])) { if (string.IsNullOrWhiteSpace(dataSourceLocation)) { return; } if (!dataSourceLocation.StartsWith(RelativePath)) { return; } if (string.IsNullOrWhiteSpace(args.ContextItemPath)) { return; } string subFolderPath = args.ContextItemPath + dataSourceLocation.Substring(1); if (args.ContentDatabase.GetItem(subFolderPath) != null) { return; } Item currentItem = args.ContentDatabase.GetItem(args.ContextItemPath); if (currentItem == null) { return; } string newItemName = dataSourceLocation.Substring(2); using (new SecurityDisabler()) { currentItem.Add(newItemName, FolderTemplate); } } }
public void Process(GetRenderingDatasourceArgs args) { foreach (var location in new ListString(args.RenderingItem["Datasource Location"])) { if (location.StartsWith("query:")) { Item contextItem = args.ContentDatabase.Items[args.ContextItemPath]; if (contextItem != null) { string query = location.Substring("query:".Length); Item queryItem = contextItem.Axes.SelectSingleItem(query); if (queryItem != null) { args.DatasourceRoots.Add(queryItem); } } } } }
private static void CreateDatasource(GetRenderingDatasourceArgs args, string datasourceLocation) { var itemPath = args.ContextItemPath + datasourceLocation.Remove(0, 1); var item = args.ContentDatabase.GetItem(itemPath); var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath, args.ContentLanguage); if (item == null && contextItem != null) { item = AddDataFolderItem(datasourceLocation, contextItem); } args.DatasourceRoots.Add(item); var datasourceItem = AddDatasourceItem(args, item); if (datasourceItem != null) { args.CurrentDatasource = datasourceItem.Paths.FullPath; } }
public void Process_DatasourceProviderIsNotNull_SourcesAndTemplateAreSet(IDatasourceProvider sourceProvider, [Substitute] DatasourceProviderFactory factory, DbItem renderingItem, Db db, string settingName, Item[] sources, Item sourceTemplate) { var processor = new GetDatasourceLocationAndTemplateFromSite(factory); sourceProvider.GetDatasources(Arg.Any <string>(), Arg.Any <Item>()).Returns(sources); sourceProvider.GetDatasourceTemplate(Arg.Any <string>(), Arg.Any <Item>()).Returns(sourceTemplate); factory.GetProvider(Arg.Any <Database>()).Returns(sourceProvider); var setting = settingName.Replace("-", string.Empty); renderingItem.Add(new DbField("Datasource Location") { { "en", $"site:{setting}" } }); db.Add(renderingItem); var rendering = db.GetItem(renderingItem.ID); var args = new GetRenderingDatasourceArgs(rendering); processor.Process(args); args.DatasourceRoots.Should().Contain(sources); args.Prototype.Should().Be(sourceTemplate); }
public void Process_LocalDatasourceExists_ShouldResolveDatasourceRoot(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var datasourceFolder = contextItem.Add("_Local", contextItem.Template); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = contextItem.Paths.FullPath }; //act processor.Process(getRenderingDatasourceArgs); //assert getRenderingDatasourceArgs.DatasourceRoots.First().ID.Should().Be(datasourceFolder.ID); }
public void Process(GetRenderingDatasourceArgs args) { Assert.IsNotNull(args, "args"); Sitecore.Data.Items.RenderingItem rendering = new Sitecore.Data.Items.RenderingItem(args.RenderingItem); UrlString urlString = new UrlString(rendering.Parameters); var contentFolder = urlString.Parameters[CONTENT_FOLDER_TEMPLATE_PARAM]; if (string.IsNullOrEmpty(contentFolder)) { return; } if (!ID.IsID(contentFolder)) { Log.Warn(string.Format("{0} for Rendering {1} contains improperly formatted ID: {2}", CONTENT_FOLDER_TEMPLATE_PARAM, args.RenderingItem.Name, contentFolder), this); return; } string text = args.RenderingItem["Datasource Location"]; if (!string.IsNullOrEmpty(text)) { if (text.StartsWith("./") && !string.IsNullOrEmpty(args.ContextItemPath)) { var itemPath = args.ContextItemPath + text.Remove(0, 1); var item = args.ContentDatabase.GetItem(itemPath); var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath); if (item == null && contextItem != null) { string itemName = text.Remove(0, 2); //if we create an item in the current site context, the WebEditRibbonForm will see an ItemSaved event and think it needs to reload the page using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system"))) { contextItem.Add(itemName, new TemplateID(ID.Parse(contentFolder))); } } } } }
protected void SetContent(ClientPipelineArgs args) { Predicate<VariableValueItemStub> match = null; Predicate<VariableValueItemStub> predicate2 = null; ID id; string str = args.Parameters["variationid"]; if (string.IsNullOrEmpty(str)) { SheerResponse.Alert("Item not found.", new string[0]); } else { id = ShortID.DecodeID(str); if (args.IsPostBack) { if (args.HasResult) { List<VariableValueItemStub> variableValues = VariableValues; if (match == null) { match = v => v.Id == id; } VariableValueItemStub stub = variableValues.Find(match); if (stub != null) { stub.Datasource = args.Result; var output = new HtmlTextWriter(new StringWriter()); RenderContentControls(output, stub); SheerResponse.SetOuterHtml(str + "_content", output.InnerWriter.ToString()); VariableValues = variableValues; } } } else { if (predicate2 == null) { predicate2 = v => v.Id == id; } VariableValueItemStub stub2 = VariableValues.Find(predicate2); if ((stub2 != null) && ((Rendering != null) && !string.IsNullOrEmpty(Rendering.ItemID))) { Item renderingItem = Client.ContentDatabase.GetItem(Rendering.ItemID); if (renderingItem == null) { SheerResponse.Alert("Item not found.", new string[0]); } else { //get current content item Item variantSourceItem = (ContextItemUri == null) ? null : Client.ContentDatabase.GetItem(ContextItemUri.ToDataUri()); if (variantSourceItem.IsNotNull()) { //use variant mapping functionality to find proper source MultiVariantProcessor processor = new MultiVariantProcessor(); IMultiVariantMapping mapping = processor.GetMapping(variantSourceItem.TemplateID.ToString(), Client.ContentDatabase); if(mapping != null) { //set mapping variantSourceItem = mapping.VariantSource(variantSourceItem); } } var args3 = new GetRenderingDatasourceArgs(renderingItem); args3.FallbackDatasourceRoots = new List<Item> {variantSourceItem}; args3.ContentLanguage = ((variantSourceItem != null) ? variantSourceItem.Language : null); args3.ContextItemPath = (variantSourceItem != null) ? variantSourceItem.Paths.FullPath : string.Empty; args3.ShowDialogIfDatasourceSetOnRenderingItem = true; args3.CurrentDatasource = (string.IsNullOrEmpty(stub2.Datasource) ? Rendering.Datasource : stub2.Datasource); GetRenderingDatasourceArgs args2 = args3; CorePipeline.Run("getRenderingDatasource", args2); if (string.IsNullOrEmpty(args2.DialogUrl)) { SheerResponse.Alert("An error ocurred.", new string[0]); } else { SheerResponse.ShowModalDialog(args2.DialogUrl, "460px", "460px", string.Empty, true); args.WaitForPostBack(); } } } } } }
public void LaunchDmsPollWizard(GetRenderingDatasourceArgs args) { if (((args != null) && (args.RenderingItem != null)) && (args.RenderingItem.ID.ToString() == PollConstants.PollRenderingID)) { Item item = args.ContentDatabase.Items.GetItem(args.ContextItemPath); if (item != null) { string str = string.Format("/sitecore/shell/default.aspx?xmlcontrol=DMSPollWizard&id={0}&language={1}&showpageeditorfunctionality=False", item.ID, item.Language.Name); args.DialogUrl = str; } } }
public void Process(GetRenderingDatasourceArgs args) { KernelContainer.Inject(this); this.DoGetRenderingDatasource(args); }
protected abstract void DoGetRenderingDatasource(GetRenderingDatasourceArgs args);
public void Process_SupportsLocalDatasourceFieldNotSet_ShouldReturnEmptyRoots(GetLocalDatasourceLocation processor, Db db, [Content] Item renderingItem) { var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem); //act processor.Process(getRenderingDatasourceArgs); //assert getRenderingDatasourceArgs.DatasourceRoots.Should().BeEmpty(); }
public void Process_DatasourceTemplateNotSet_ShouldReturnEmptyRoots(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = contextItem.Paths.FullPath }; //act using (new SettingsSwitcher("Foundation.LocalDatasource.LocalDatasourceFolderTemplate", ID.NewID.ToString())) { processor.Process(getRenderingDatasourceArgs); } //assert getRenderingDatasourceArgs.DatasourceRoots.Should().BeEmpty(); }
/// <summary> /// The create pipeline args. /// </summary> /// <param name="args"> /// The args. /// </param> /// <param name="renderingItem"> /// The rendering item. /// </param> /// <returns> /// </returns> private static GetRenderingDatasourceArgs CreatePipelineArgs(ClientPipelineArgs args, Item renderingItem) { Item clientContentItem = WebEditUtil.GetClientContentItem(Client.ContentDatabase); GetRenderingDatasourceArgs getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { FallbackDatasourceRoots = new System.Collections.Generic.List<Item> { Client.ContentDatabase.GetRootItem() }, ContentLanguage = (clientContentItem != null) ? clientContentItem.Language : null, ContextItemPath = (clientContentItem != null) ? clientContentItem.Paths.FullPath : string.Empty, ShowDialogIfDatasourceSetOnRenderingItem = true }; LayoutDefinition currentLayoutDefinition = SetDatasource.GetCurrentLayoutDefinition(); ID clientDeviceId = WebEditUtil.GetClientDeviceId(); string uniqueId = args.Parameters["uniqueId"]; if (currentLayoutDefinition != null && !ID.IsNullOrEmpty(clientDeviceId)) { RenderingDefinition renderingByUniqueId = currentLayoutDefinition.GetDevice(clientDeviceId.ToString()).GetRenderingByUniqueId(uniqueId); if (renderingByUniqueId != null) { getRenderingDatasourceArgs.CurrentDatasource = renderingByUniqueId.Datasource; } } return getRenderingDatasourceArgs; }
public void Process_ContextItemNotSet_ShouldReturnEmptyRoots(GetLocalDatasourceLocation processor, Db db, [Content] Item contextItem, [Content] DbTemplate template) { //arrange db.Add(new DbItem("rendering") { { Templates.RenderingOptions.Fields.SupportsLocalDatasource, "1" } }); var renderingItem = db.GetItem("/sitecore/content/rendering"); var getRenderingDatasourceArgs = new GetRenderingDatasourceArgs(renderingItem) { ContextItemPath = ID.NewID.ToString() }; //act processor.Process(getRenderingDatasourceArgs); //assert getRenderingDatasourceArgs.DatasourceRoots.Should().BeEmpty(); }