Exemplo n.º 1
0
        public IEnumerable <MatrixFieldCell> BuildMatrixTable(MatrixFieldPredefinedListEditorSettings fieldsettings) //maps to GetEvents()
        {
            //row options
            var rowOptions = new List <SelectListItem>();

            foreach (var option in fieldsettings.Options)
            {
                rowOptions.Add(new SelectListItem {
                    Text = option.Value, Value = option.Name
                });
            }
            //column options
            var columnOptions = new List <SelectListItem>();

            foreach (var option in fieldsettings.ColumnOptions)
            {
                columnOptions.Add(new SelectListItem {
                    Text = option.Value, Value = option.Name
                });
            }

            // Add events (column elements) for each content type (row element) e.g. article.created
            foreach (var typeDefinition in rowOptions)
            {
                foreach (var contentEvent in columnOptions)
                {
                    yield return(CreateEvent(typeDefinition.Value.ToLower(), contentEvent.Value.ToLower(), typeDefinition.Text, category: "RowElement"));
                }
            }

            // Add events for all content type events (column elements) e.g. content.created, content.published
            // foreach (var contentEvent in ContentEvents.AllEvents)
            foreach (var columnOption in fieldsettings.ColumnOptions)
            {
                yield return(CreateEvent("content", columnOption.Value, category: "Content"));
            }
        }
Exemplo n.º 2
0
        public HashSet <string> NormalizeMatrixCells(IEnumerable <string> submittedEvents, MatrixFieldPredefinedListEditorSettings fieldsettings)
        {
            if (submittedEvents == null)
            {
                throw new ArgumentNullException(nameof(submittedEvents));
            }



            var normalizedEvents = new HashSet <string>();
            var events           = BuildMatrixTable(fieldsettings).ToList();

            // Verify the events only consist of those defined by this provider
            foreach (var @event in submittedEvents)
            {
                if (events.Any(e => e.Name == @event))
                {
                    normalizedEvents.Add(@event);
                }
            }


            //column options
            var columnOptions = new List <SelectListItem>();

            foreach (var option in fieldsettings.ColumnOptions)
            {
                columnOptions.Add(new SelectListItem {
                    Text = option.Value, Value = option.Name
                });
            }
            // When a content.{eventName} event is being subscribed to, remove all other *.{eventName}
            // since the 'content' event implies a subscription to all content events of that type.
            foreach (var contentEvent in columnOptions)// ContentEvents.AllEvents)
            {
                if (normalizedEvents.Contains($"content.{contentEvent.Value}"))
                {
                    normalizedEvents.RemoveWhere(e => !e.StartsWith("content.") && e.EndsWith($".{contentEvent.Value}"));
                }
            }

            return(normalizedEvents);
        }