/// <summary>
        /// Gets the list of placeholder settings items attached to the context item for the
        /// specified placeholder key.
        /// </summary>
        /// <param name="placeholderKey">The placeholder key.</param>
        /// <param name="database">The database context.</param>
        /// <param name="layoutDefinition">The context item's layout definition.</param>
        /// <returns>The list of placeholder settings items.</returns>
        public static IEnumerable <Item> GetPlaceholderItems(string placeholderKey, Database database, string layoutDefinition)
        {
            Assert.ArgumentNotNull(placeholderKey, nameof(placeholderKey));
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(layoutDefinition, nameof(layoutDefinition));

            // Gets the list of placeholder definitions defined in the 'Layout' field of the context item
            placeholderKey = placeholderKey.ToLowerInvariant();
            IEnumerable <PlaceholderDefinition> placeholderDefinitions = GetPlaceholderDefinitionList(layoutDefinition, placeholderKey);
            List <Item> placeholderItems = new List <Item>();

            // Maps the placeholder definitions to a list of placeholder settings items by calling to the database
            if (placeholderDefinitions != null && placeholderDefinitions.Any())
            {
                foreach (var placeholderDefinition in placeholderDefinitions)
                {
                    string metaDataItemId = placeholderDefinition.MetaDataItemId;
                    if (!string.IsNullOrEmpty(metaDataItemId))
                    {
                        using (new SecurityDisabler())
                            placeholderItems.Add(database.GetItem(metaDataItemId));
                    }
                }

                return(placeholderItems.Distinct(new ItemEqualityComparer()));
            }
            // If there are no placeholder definitions then fall back to base behavior
            else
            {
                PlaceholderCache placeholderCache = PlaceholderCacheManager.GetPlaceholderCache(database.Name);
                Item             obj = placeholderCache[placeholderKey];
                if (obj != null)
                {
                    return new[] { obj }
                }
                ;
                int num = placeholderKey.LastIndexOf('/');
                if (num >= 0)
                {
                    string index = StringUtil.Mid(placeholderKey, num + 1);

                    obj = placeholderCache[index];
                }
                return(obj == null?Enumerable.Empty <Item>() : new[] { obj });
            }
        }
Beispiel #2
0
 public SiteSpecificPlaceholderCache(string databaseName, string siteName, PlaceholderCache fallbackCache)
     : base(databaseName)
 {
     this.FallbackCache = fallbackCache;
     this.Site          = siteName == null ? null : Factory.GetSite(siteName);
 }