Exemplo n.º 1
0
        public Task <VisualEditorState> GetCurrentAsync()
        {
            if (_visualEditorStateCache == null)
            {
                _visualEditorStateCache = new VisualEditorState();
            }

            return(Task.FromResult(_visualEditorStateCache));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the cache value or null if it has not been set.
        /// </summary>
        public void Set(VisualEditorState data)
        {
            var cache = _httpContextAccessor.HttpContext?.Items;

            if (cache == null)
            {
                throw new InvalidOperationException("Cannot set the cache outside of a request.");
            }

            cache[CACHE_KEY] = data;
        }
Exemplo n.º 3
0
        private async Task <string> RenderBlocksToHtml(
            PageRegionRenderDetails pageRegion,
            Dictionary <string, string> regionAttributes,
            VisualEditorState visualEditorState
            )
        {
            // No _permittedBlocks means any is allowed.
            var blocksToRender = pageRegion
                                 .Blocks
                                 .Where(m => _permittedBlocks.Count == 0 || _permittedBlocks.Contains(m.BlockType.FileName));

            var blockHtmlParts = new List <string>();

            foreach (var block in blocksToRender)
            {
                var renderedBlock = await _blockRenderer.RenderBlockAsync(_viewContext, _pageViewModel, block);

                blockHtmlParts.Add(renderedBlock);
            }

            string blocksHtml = string.Empty;

            if (blockHtmlParts.Any())
            {
                if (!_allowMultipleBlocks)
                {
                    // If for some reason another block has been added in error, make sure we only display one.
                    blocksHtml = blockHtmlParts.Last();
                }
                else
                {
                    blocksHtml = string.Join(string.Empty, blockHtmlParts);
                }
            }
            else
            {
                regionAttributes.Add("data-cms-page-region-empty", string.Empty);

                if (!_allowMultipleBlocks && visualEditorState.VisualEditorMode == VisualEditorMode.Edit)
                {
                    // If there are no blocks and this is a single block region
                    // add a placeholder element so we always have a menu
                    blocksHtml = _blockRenderer.RenderPlaceholderBlock(_emptyContentMinHeight);
                }
            }

            return(blocksHtml);
        }