Exemple #1
0
        private void FillRenderedItemsForSnippets(RenderedItem rendered, RenderedJsonRendering element)
        {
            if (rendered == null || !rendered.Placeholders.First().Elements.Any())
            {
                return;
            }

            if (!rendered.Placeholders.First().Elements.Any())
            {
                return;
            }

            element.Placeholders.FirstOrDefault()?.Elements?.Clear();

            var renderedPlaceholderElements = rendered.Placeholders.FirstOrDefault()?.Elements;

            if (renderedPlaceholderElements == null)
            {
                return;
            }

            foreach (var renderedPlaceholderElement in renderedPlaceholderElements)
            {
                element.Placeholders.FirstOrDefault()?.Elements
                .Add(renderedPlaceholderElement);
            }
        }
Exemple #2
0
        /// <inheritdoc/>
        protected override void SetResult(RenderJsonRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));
            Assert.IsNotNull(args.Result, "args.Result should not be null");

            var rendering = new RenderedJsonRendering(args.Result);

            if (rendering.RenderingParams == null)
            {
                return;
            }

            if (!rendering.RenderingParams.Keys.Any(o => o.StartsWith(GridParamsKey)))
            {
                return;
            }

            var db = args.Rendering?.Item?.Database;

            if (db == null)
            {
                return;
            }

            for (int i = 1; i < 9; i++)
            {
                if (!rendering.RenderingParams.ContainsKey(GridParamsKey + i))
                {
                    break;
                }

                var gridParameters = rendering.RenderingParams[GridParamsKey + i];
                var cssClasses     = new List <string>();
                foreach (var id in Sitecore.MainUtil.Split(gridParameters, "|"))
                {
                    var item = db.GetItem(id);
                    if (item == null)
                    {
                        continue;
                    }

                    var css = item[GridCssKey];
                    if (!string.IsNullOrWhiteSpace(css))
                    {
                        cssClasses.Add(css);
                    }
                }

                if (cssClasses.Any())
                {
                    rendering.RenderingParams[GridParamsKey + i] = string.Join(" ", cssClasses);
                }
            }

            args.Result = rendering;
        }
Exemple #3
0
        private ID GetIdFromDataSource(Item item, RenderedJsonRendering renderedJsonRendering)
        {
            ID datasourceId;

            datasourceId = !ID.TryParse(renderedJsonRendering.DataSource, out var parsedDatasourceId)
                            ? item.Database.GetItem(renderedJsonRendering.DataSource)?.ID
                            : parsedDatasourceId;

            return(datasourceId);
        }
Exemple #4
0
        private bool CheckSnippetsContainsRecursiveElements(
            Item item,
            IRenderingConfiguration renderingConfiguration,
            int nestingLevel,
            RenderedJsonRendering rendering)
        {
            var datasourceItem    = item.Database.GetItem(rendering.DataSource);
            var renderedRendering = GetRenderedElement(renderingConfiguration, datasourceItem);

            foreach (var renderedRenderingPlaceholder in renderedRendering.Placeholders)
            {
                if (renderedRenderingPlaceholder.Elements.Any(
                        renderingPlaceholderElement => ContainsRecursiveRenderedRendering(
                            item,
                            renderingPlaceholderElement,
                            renderingConfiguration,
                            nestingLevel)))
                {
                    return(true);
                }
            }

            return(false);
        }
 public ExtensibleRenderedJsonRendering(RenderedJsonRendering innerRendering, string renderingConfigurationName, Rendering rendering)
     : base(innerRendering)
 {
     RenderingConfigurationName = renderingConfigurationName ?? throw new ArgumentNullException(nameof(renderingConfigurationName));
     Rendering = rendering ?? throw new ArgumentNullException(nameof(rendering));
 }