Esempio n. 1
0
        /// <summary>
        /// Gets the fallback value.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        public virtual string GetFallbackValue(Field field)
        {
            Assert.ArgumentNotNull(field, "field");

            Item item = field.Item;

            Assert.ArgumentNotNull(item, "item");

            Logger.Debug(">> GetFallbackValue - s:{0} db:{1} i:{2} f:{3}", Sitecore.Context.GetSiteName(), item.Database.Name, item.ID, field.Name);
            Logger.PushIndent();

            string value = null;

            try
            {
                // test cache first
                value = Cache.GetFallbackValue(item, field);

                // we have a cached value.. return it.
                if (value != null)
                {
                    Logger.Debug("Value found in the cache");
                    return(value);
                }

                // Call the fieldFallback pipeline
                var pipelineArgs = new FieldFallbackPipelineArgs(field);
                Sitecore.Pipelines.CorePipeline.Run("fieldFallback", pipelineArgs);

                // if the args has a value, then one of the processors fell back to something
                if (pipelineArgs.HasFallbackValue)
                {
                    Logger.Debug("Fallback Found");

                    // put it in the cache
                    Cache.AddFallbackValues(item, field, pipelineArgs.FallbackValue);
                    return(pipelineArgs.FallbackValue);
                }

                Logger.Debug("No fallback");
                return(null);
            }
            finally
            {
                Logger.PopIndent();
                Logger.Debug("<< GetFallbackValue");
            }
        }