Ejemplo n.º 1
0
 public void Process(PipelineArgs args)
 {
     if (ServiceLocator.ServiceProvider.GetService <IConfiguration <CompositesConfiguration> >().GetConfiguration().OnPageEditingEnabled)
     {
         IInsertRenderingArgs insertRenderingsArgs = args as IInsertRenderingArgs;
         ServiceLocator.ServiceProvider.GetService <IOnPageEditingContextService>().ExperienceEditorAction = (args as IPageEditorActionArgs)?.Name;
         if (insertRenderingsArgs != null && insertRenderingsArgs.Datasource == null && WebUtil.GetFormValue("datasource").IsNullOrEmpty() && Regex.IsMatch(insertRenderingsArgs.PlaceholderKey, "section-(title|content)") && insertRenderingsArgs.Layout.Devices.Cast <DeviceDefinition>().FirstOrDefault((DeviceDefinition d) => d.ID == insertRenderingsArgs.Device.ID) != null)
         {
             LayoutModel layoutModel             = new LayoutModel(insertRenderingsArgs.Layout.ToXml());
             Item        compositeDatasourceItem = ServiceLocator.ServiceProvider.GetService <ICompositeService>().GetCompositeDatasourceItem(insertRenderingsArgs.PlaceholderKey, insertRenderingsArgs.ContextItem, layoutModel, new ID(insertRenderingsArgs.Device.ID));
             insertRenderingsArgs.Datasource = compositeDatasourceItem;
         }
     }
 }
        public void Process(PipelineArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            IInsertRenderingArgs insertRenderingArgs = args as IInsertRenderingArgs;

            if (insertRenderingArgs == null)
            {
                return;
            }

            Item renderingItem = insertRenderingArgs.RenderingItem;

            Assert.IsNotNull((object)renderingItem, "renderingItem");
            string placeholderKey = insertRenderingArgs.PlaceholderKey;

            Assert.IsNotNullOrEmpty(placeholderKey, "placeholderKey");
            string lastPart = StringUtil.GetLastPart(placeholderKey, '/', placeholderKey);

            string[] arrKey      = lastPart.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            string   lastPartKey = arrKey[0];

            RenderingDefinition renderingDefinition = new RenderingDefinition()
            {
                ItemID      = renderingItem.ID.ToString(),
                Placeholder = lastPartKey
            };

            if (insertRenderingArgs.Datasource != null)
            {
                renderingDefinition.Datasource = insertRenderingArgs.Datasource.ID.ToString();
            }

            Assert.IsNotNull((object)insertRenderingArgs.Device, "device");

            this.InsertRenderingAt(insertRenderingArgs.Device, renderingDefinition, insertRenderingArgs.Position, insertRenderingArgs.AllowedRenderingsIds, arrKey[1]);

            insertRenderingArgs.Result = new RenderingReference(renderingDefinition, insertRenderingArgs.Language, insertRenderingArgs.ContentDatabase);
        }