Isn't there a problem in Core\Content\shapes.cs

Topics: Customizing Orchard, General, Troubleshooting
Jan 22, 2013 at 7:37 PM
Edited Jan 22, 2013 at 10:32 PM

In Discover, some comments and code are inverted, it seems that code is bad ?

                    if (contentItem != null) {
                        // Alternates in order of specificity. 
                        // Display type > content type > specific content > display type for a content type > display type for specific content

                        // Content__[DisplayType] e.g. Content.Summary
                        displaying.ShapeMetadata.Alternates.Add("Content_" + EncodeAlternateElement(displaying.ShapeMetadata.DisplayType));

                        // Content__[ContentType] e.g. Content-BlogPost
                        displaying.ShapeMetadata.Alternates.Add("Content__" + EncodeAlternateElement(contentItem.ContentType));

                        // Content__[Id] e.g. Content-42
                        displaying.ShapeMetadata.Alternates.Add("Content__" + contentItem.Id);

                        // Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
                        displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));

                        // Content_[DisplayType]__[Id] e.g. Content-42.Summary
                        displaying.ShapeMetadata.Alternates.Add("Content_" +  displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
                    }
Jan 25, 2013 at 10:43 AM
Edited Jan 25, 2013 at 10:58 AM

Testing this (keeping the old code for compatibility

 

                        // Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary -> CS: this is the corresponding sample would rather  Content.Summary.BlogPost which is implemented by next code (bug ?)
                        displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "__" + EncodeAlternateElement(contentItem.ContentType));
                        //CS 01/25/13 inverted code  for Content-[ContentType]_[DisplayType]__ e.g.  Content-BlogPost.Summary
                        displaying.ShapeMetadata.Alternates.Add("Content_" + EncodeAlternateElement(contentItem.ContentType + "__" + displaying.ShapeMetadata.DisplayType));

                        // Content_[DisplayType]__[Id] e.g. Content-42.Summary  -> CS: this is the corresponding sample would rather  Content.Summary.42 which is implemented by next code (bug ?)
                        displaying.ShapeMetadata.Alternates.Add("Content_" +  displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
                        //CS 01/25/13 inverted code  for Content-[Id]__[DisplayType] e.g. Content-42.Summary
                        displaying.ShapeMetadata.Alternates.Add("Content_" + contentItem.Id + "__" + displaying.ShapeMetadata.DisplayType);

Coordinator
Feb 10, 2013 at 7:24 AM
What do you mean? I'm sorry, I don't see what the problem is.
Feb 10, 2013 at 9:10 AM
I have reverted my change, not sure of effect and hard to trace due to Clay

but could you explain why the comment being
// Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary

the code builds
displaying.ShapeMetadata.Alternates.Add("Content_" + displaying.ShapeMetadata.DisplayType + "_" + EncodeAlternateElement(contentItem.ContentType));
which is Content_Summary_BlogPost


and when
// Content_[DisplayType]__[Id] e.g. Content-42.Summary
the code build
displaying.ShapeMetadata.Alternates.Add("Content
" + displaying.ShapeMetadata.DisplayType + "__" + contentItem.Id);
which is Content_Summary__42
Coordinator
Feb 10, 2013 at 9:09 PM
The first code excerpt builds Content_Summary__BlogPost. Notice the double underscore that will translate to a file name of Content.BlogPost-Summary.cshtml. So that's what the comments should be corrected to reflect. I'm doing it now... And, it's done (changeset 3853b32352b3). Thanks for the heads up.