For the benefit of the archives, here is a blog post on the solution I 
eventually came up with for this problem:

http://blog.library.villanova.edu/libtech/2012/06/25/moving-vufind-to-zend-framework-2-part-3-theme-inheritance/

I'm very interested in feedback on my solution if anyone cares to share any.

Also, many thanks to saschaH from the IRC channel, who was instrumental in 
putting me on the right track when I was stuck (by pointing out that another 
solution to my view resolver problem was simply to push a path stack into the 
existing view resolver on the fly, outside of the configuration file).

- Demian

From: Demian Katz
Sent: Tuesday, June 19, 2012 3:38 PM
To: fw-general@lists.zend.com
Subject: Theme inheritance in ZF2

The application I am trying to port from ZF1 to ZF2 uses a theme inheritance 
system inspired by list8D's solution:

http://blogs.kent.ac.uk/list8d/2009/10/29/creating-a-themable-application-in-zend/

Essentially, each theme has its own directory along with a configuration that 
may specify a parent theme from which it inherits files.  A path stack is 
generated using the current user-selected theme and any parent(s).  The themes 
hold static resources, templates and view helpers.

My first obstacle in porting this over is figuring out how to configure ZF2's 
view resolver to deal with the appropriate path stack.  It seems like there are 
two options:


1.)    Do some work to dynamically generate the 
['view_manager']['template_path_stack'] value in the module configuration.  
This seems completely wrong: my application needs to be configured in order to 
find out which theme is currently active (current theme is determined by a 
combination of configuration, request parameters and device detection), and any 
solution involving dynamic configuration generation would run into 
chicken-and-egg issues.

2.)    Write a custom implementation of Zend\View\Resolver\ResolverInterface 
that deals with theme issues "on demand."  This feels like the more appropriate 
solution, but I'm not sure how to go about telling Zend\Mvc\View\ViewManager to 
use a custom resolver.  A few specific issues:

a.       The ViewManager's getResolver() method seems rather hard-coded, and I 
don't see a corresponding setResolver() method.

b.      Even if there were a setResolver, I'm not sure where best to set this 
up (presumably it will require hooking an event that's roughly equivalent to 
ZF1's dispatchLoopStartup plugin method, but my understanding of the new MVC is 
still a bit fuzzy).

c.       It's not clear to me how the configuration example in the QuickStart 
(http://packages.zendframework.com/docs/latest/manual/en/zend.view.html#zend.view.quick-start.usage)
 correlates to beta4 and the ZendSkeletonApplication example.

I'm still very new to ZF2 and have a lot of learning to do, so apologies if I'm 
missing something obvious - any suggestions or pointers in the right general 
direction would be greatly appreciated.

Also, I understand that this theme solution is not necessarily in line with 
ZF2's goals of improved efficiency; I do understand why path stacks are not 
recommended as the default approach.  However, for my particular use case, I 
think I need to sacrifice some performance in the interest of flexibility and 
extensibility.  Obviously, if anyone has a better idea, I'm happy to hear it.

Thanks for your time!  If I can actually get this working in a reasonable way, 
I'll be happy to share code with anyone else who might be interested.

Demian

Reply via email to