예제 #1
0
        /// <summary>
        /// Programmatically retrieves an edit frame. The HTML to construct the start and end of the edit frame are setup in the Datasource.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="controller"></param>
        private void SetEditDatasourceEditFrame(IComponentModelBase model, Controller controller)
        {
            var htmlHelper = controller.GetHtmlHelper();
            EditFrameRendering editFrame = new EditFrameRendering(htmlHelper.ViewContext.Writer, model.DataSourcePath, _editFrameLocation, "Edit Component", string.Empty, string.Empty, null);

            model.EditDatasourceStart = editFrame.EditFrameStart();
            model.EditDatasourceEnd   = editFrame.EditFrameEnd();
        }
예제 #2
0
        /// <summary>
        /// Sets up the linked items in the model.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="datasource"></param>
        private void SetLinkedItems(IComponentModelBase model, Guid datasource)
        {
            var linkedItems = GetLinkedItems(Sitecore.Context.Database, Sitecore.Context.Language, Sitecore.Context.Database.GetItem(new ID(datasource)));

            if (linkedItems.Length > 0)
            {
                model.LinkedItems = linkedItems.ToList().GroupBy(x => x.ID).Select(x => _glassService.GetItem <GlassBase>(x.Key.Guid)).ToList();
            }
            model.LinkedItemCount = model.LinkedItems?.Count() ?? 0;
        }
예제 #3
0
        /// <summary>
        /// Uses the current Rendering context to setup basic fields in the model with information regarding the current rendering.
        /// Most of the processing in this method only happens if the content editor is in IsExperienceEditorEditing.
        /// </summary>
        /// <param name="model">A POCO object that will hold reference to our Rendering details</param>
        /// <param name="controller">A reference to the controller that is calling this method. This is needed for access to the HtmlHelper </param>
        public void PopulateStandardExperienceResponse(ref IComponentModelBase model, Controller controller)
        {
            if (model == null)
            {
                return;
            }

            actingController = controller;
            try
            {
                model.IsExperienceEditorEditing = Context.PageMode.IsExperienceEditorEditing;

                var currentRendering = RenderingContext.CurrentOrNull?.Rendering;

                model.IsDataSourceSet = !string.IsNullOrWhiteSpace(currentRendering.DataSource);
                model.RenderingName   = currentRendering.RenderingItem.Name;
                model.RenderingId     = currentRendering.Id.ToString();

                if (model.IsDataSourceSet && model.IsExperienceEditorEditing)
                {
                    model.DataSourceCount      = currentRendering.DataSource.Count();
                    model.DataSourceIdentifier = currentRendering.DataSource;

                    Guid datasource = Guid.Empty;
                    if (Guid.TryParse(model.DataSourceIdentifier, out datasource))
                    {
                        var dataSourceItem = _glassService.GetItem <GlassBase>(datasource);
                        model.DataSourceName = dataSourceItem.Name;
                        model.DataSourcePath = dataSourceItem.FullPath;
                        SetLinkedItems(model, datasource);
                    }

                    SetEditDatasourceEditFrame(model, controller);
                }

                if (model.IsExperienceEditorEditing)
                {
                    var conditionalRenderings = GetPersonalizedRenderings(currentRendering);
                    model.HasConditionalRenderings = conditionalRenderings.Any();
                    if (model.HasConditionalRenderings)
                    {
                        model.Rules = GetRulesForRendering(conditionalRenderings.FirstOrDefault());
                    }
                }
            }
            catch (Exception ex)
            {
                model.ErrorOccurred = true;
                model.ErrorMessage  = ex.Message;
            }
        }