HedgehogDevelopment / sitecore-field-fallback

Sitecore Field Fallback Module
http://marketplace.sitecore.net/en/Modules/Field_Fallback.aspx
Apache License 2.0
8 stars 12 forks source link

FallbackDisabler is disabled after a call to GlassController.GetRenderingParameters<T>() #18

Closed seankearney closed 9 years ago

seankearney commented 9 years ago

We are seeing that fallback isn't working after a call to GlassController.GetRenderingParameters()

Glass code goes and creates an in-memory Sitecore item via this and this

Basically – Glass goes and creates a fake, in memory, Sitecore item. This triggers events to be fired in Sitecore. Specifically it triggers the AddingVersion and SavingItem events. It should also trigger the AddedVersion and SavedItem events; it does not fire the last two.

The field fallback module responds to the Adding/Saving events and disables FieldFallback. When it sees Added/Saved it is re-enabled. Being we aren’t seeing the closing events Field Fallback stays disabled!

I’ve registered a bug with Sitecore #442839. Here is a simple script to duplicate Sitecore bug

cc: @mikeedwards83

seankearney commented 9 years ago

Sitecore's response thus far is:

The AddedVersion and SavedItem events are database specific. Because of the creating the item in memory without parent item, it does not appears in the database. That’s why you cannot see these events. If you want to see them, you have to create item with the parent

seankearney commented 9 years ago

A potential workaround for this issue could be to override the GlassController's GetRenderingParameters method.

public class CustomController : GlassController
{
    protected override T GetRenderingParameters<T>()
    {
        // Sitecore bug 442839... we need to manually raise two events until the bug is fixed
        // Field fallback bug - https://github.com/HedgehogDevelopment/sitecore-field-fallback/issues/18
        // https://github.com/mikeedwards83/Glass.Mapper/issues/158

        using (new Sitecore.Data.Events.EventDisabler())
        {
            return base.GetRenderingParameters<T>();
        }
    }
}