Nico Knoll Posted December 28, 2011 Share Posted December 28, 2011 Hi, how can I add a field to "setup"->"template"->"URLs"? Greets, Nico Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 Right now this one isn't hookable, so the only way is by modifying the markup returned by ProcessField::executeEdit. That's not a very desirable way to do it. I will plan to make this one hookable when I get back to the office after the holiday. Following that, it should be easy to hook into it and I'll post an example. Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2011 Author Share Posted December 29, 2011 Well, in the meantime I added just "___" and now it's hookable. Would be beautiful if you could make as much functions hookable as possible! Greets, Nico Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 I would have made everything hookable the first time, except that hooks are somewhat of a compromise, so I take a more cautious route and add them as needed. Functions that are hookable don't execute quite as quickly as they would if they were native PHP. However, in this case where the functions are called once per request, it makes sense for everything to be hookable. It's the things that get called a few hundred times a request that I implement more cautiously. In this case, I'm just going to make all the form generation functions hookable so that you can hook directly into any one of those tabs very easily. While at it, I'll do the same thing with ProcessField. Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2011 Author Share Posted December 29, 2011 OK. And by the way: is there a way to use wire('config') in the init part of a module? It always returns NULL... Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 And by the way: is there a way to use wire('config') in the init part of a module? It always returns NULL... So long as ProcessWire is booting your module, wire('config') should always be available. In fact, it's the first API var that ProcessWire sets and it's added to the API before $modules is even instantiated. And when init() is called, all API vars should be available (excluding the requested $page). So I'm not sure how you'd get a module init() to not have access to the $config API var unless the module was being initialized somehow outside of ProcessWire? Can you tell me more about the context where this is occurring? Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2011 Author Share Posted December 29, 2011 Ok: I'm building a module which shouldn't be loaded if im in the backend. So I tried first to get the backend URL with "wire('config')->urls->admin" and second to get the template "wire('page')->template". But both return NULL. Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 Where is the module being started/instantiated? I guess this question is only applicable if you don't have 'autoload' => true; in your getModuleInfo() function(). Specifically, I'm wondering if you are doing something like: $instance = new YourModule(); somewhere outside of ProcessWire's execution path, rather than $instance = $modules->get("YourModule"); ? Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2011 Author Share Posted December 29, 2011 I've got autoload = true Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 I probably need to take a look to see what's up. Do you want to email the module file over to me? Email my first name @rc-d.net or PM it to me. Rest assured, all the $config vars should be available in any module's init() (and even __construct for that matter). Link to comment Share on other sites More sharing options...
Nico Knoll Posted December 29, 2011 Author Share Posted December 29, 2011 sent Link to comment Share on other sites More sharing options...
ryan Posted December 29, 2011 Share Posted December 29, 2011 Got it–I see what's going on. I was thinking that 'config' was not yet set, but I should have read more closely as you said it was just $config->urls->admin and $page. PW has to start loading pages before it knows what the admin URL is, so that's actually something that happens after the modules are initialized. And that's the only $config->urls property that's determined after module initialization. So what I think you'll want to add a ready() function to your module and use that instead of init() here. PW calls that ready() method after it's determined the current page but before its rendered it. So it's pretty much the same as init, except that init() happens before any page activity (should you need to add a hook before such activity occurs). Whereas ready() is more appropriate in your case since you need to know things about the requested page. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now