7

How can I make 'SiteConfiguration.MediaHelper.ShowVideoPlaceholders' equal to false?

The constructor of Sdl.Web.Mvc.Html.BaseMediaHelper seems to hardcode this to 'true'.

  • Is it not as simple as putting SiteConfiguration.MediaHelper.ShowVideoPlaceholders = false; in Application_Start() in global.asax? – Will Price Jun 25 '15 at 7:22
5

I think you can simply set this property to false in the Application_Start method of your web application global.asax. You can either directly edit the version provided with the DXA (see penultimate line in code example below), or inherit from it and override it.

    protected void Application_Start()
    {
        InitializeDependencyInjection();
        SiteConfiguration.StaticFileManager = (IStaticFileManager)DependencyResolver.Current.GetService(typeof(IStaticFileManager));
        SiteConfiguration.MediaHelper = (IMediaHelper)DependencyResolver.Current.GetService(typeof(IMediaHelper));
        SiteConfiguration.Initialize(TridionConfig.PublicationMap);
        RegisterRoutes(RouteTable.Routes);
        AreaRegistration.RegisterAllAreas();
        SiteConfiguration.MediaHelper.ShowVideoPlaceholders = false;
        initialized = true;
    }
3

The value is indeed hard-coded to true in BaseMediaHelper, so if you want to use false, you will have to create your own subclass which sets it to false and register your class instead of BaseMediaHelper in Unity.config.

  • Thanks very much Rick. Indeed this is possible. I created 'ExtendedDD4TMediaHelper' inheriting from 'BaseMediaHelper' then in the constructor I call the base and set 'base.ShowVideoPlaceholders = false;'.Then, as you said, updated my unity config to use my new class. Note: You must implement all methods already defined in the original e.g. I made a direct copy of 'GetResponsiveImageUrl'. It feels a little dirty but is necessary. – Jonathan Primmer Jun 24 '15 at 20:43
  • Can you not subclass DD4TMediaHelper and override the constructor only? – Will Price Jun 25 '15 at 7:24
  • Yes, that is what I meant. – Rick Pannekoek Jun 25 '15 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.