1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 2.0: please make all classes extendable

Discussion in 'Closed Suggestions' started by Arty, Aug 17, 2016.

  1. Arty

    Arty Well-Known Member

    In XenForo 1 there are few classes that cannot be extended. Recently I ran into inability to extend XenForo_Template_FileHandler and
    XenForo_Template_Public. Those limitations make it impossible to write add-ons that modify templates at compile time rather than run time, which might affect performance if modifications require a lot of parsing.

    Changing it for XF 1 would require too many core changes, so probably not worth doing it now. Can you please make all classes extendable in XenForo 2.0, so it would be possible to change pretty much any part of XenForo?
    ┼ŻivaAkcija and tajhay like this.
  2. Valhalla

    Valhalla Well-Known Member

    It may be a design choice (though I appreciate what you're saying).
  3. Mike

    Mike XenForo Developer Staff Member

    FWIW, modifying templates at compile time by add-ons is generally something we have tried to avoid, simply because we intentionally don't run extended classes while upgrading (so compiler extension can block an upgrade). This is why we tend to push to run-time things or the template modification system which is something we can more easily control (since it's not modifying the compiler itself).

    I'm going to close this suggestion but not give it a particular prefix. The reason is that when a suggestion says "do something for ALL things", it's very difficult to ever consider it implementable. There may be specific reasons why a decision was made (I gave some potential examples with respect to the compiler, for example), it may be an oversight or something else. Specific, actionable suggestions are more likely to be implemented by virtue of the fact that they're concrete, rather than conceptual.

    That said, we are certainly aware of the use of statics in XF1 in some non-ideal places so we've taken steps to remove them in most situations. We're certainly aware of the general idea of what you're suggesting and have been taking it into consideration. But it'll be much more useful to suggest specific examples with an explanation of why/what you're trying to do if you run into them in XF2.
    Arty and Chris D like this.
  4. Arty

    Arty Well-Known Member

    Thank you.

    What I'm trying to do in XF1 is to make style specific template modifications. While it can be done in run time using template_post_parse event, it could be resource intensive to do that every time template is rendered, so I was looking at possibility to mess with compiled templates instead. That would require extending classes XenForo_Template_Public (to alter compiled templates) and XenForo_Template_FileHandler (to change altered compiled templates when parent template is changed/deleted).
  5. Mike

    Mike XenForo Developer Staff Member

    $visitorStyle holds information about the current style and should be available in all templates. You mention template modifications, so I'm not sure if you're referring to the system by that name, but if so, you should be able to create modifications that only apply based on the value within that.
    Arty likes this.
  6. Arty

    Arty Well-Known Member

    That wouldn't work because there is no fixed style id or name to test against. I need to apply modification to all styles that have specific style property. There is no function to check if property exists, using template condition will trigger error if property is missing.

    Why do I want that? Currently to provide support for third party add-on in my style I need to supply modified templates with style. Some add-ons have quite frequent updates that don't change more than few lines of code. Maintaining support for those add-ons requires updating modified templates with every update, which also ties my styles to specific versions of those add-ons.

    My idea is to move support for third party add-ons from style to template modifications. Since my styles already come with optional add-on that enhances some XenForo features, I want to add template modifications functionality to my add-on, so instead of providing templates for third party add-ons, my add-on would apply necessary template modifications for third party add-ons to my styles. This will help a lot with maintaining support for third party add-ons and will make it possible to support multiple versions of same third party add-on.

    So that is why I was looking for possibility to create template modifications that are applied only to specific style.
    Digital Doctor likes this.

Share This Page