netcarver Posted October 13, 2012 Share Posted October 13, 2012 (edited) I need to make the title field collapsedHidden in one of the templates that a new module creates during its install(). I couldn't work out how to do this successfully meaning that the module has some manual installation steps at the moment. In the fieldgroup of the template I added the field to I tried... $ls_fieldgroup->get('title')->set('collapsed', Inputfield::collapsedHidden); $ls_fieldgroup->save(); ... but that doesn't seem to do it. Nor does... $ls_fieldgroup->getField('title', true)->set('collapsed', Inputfield::collapsedHidden); $ls_fieldgroup->save(); Edited October 14, 2012 by netcarver Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2012 Share Posted October 13, 2012 Try this: $title = $ls_fieldgroup->get('title', true); $title->collapsed = Inputfield::collapsedHidden; wire('fields')->saveFieldgroupContext($title, $ls_fieldgroup); I could probably make this simpler from the API perspective (to work more like your code example), but only you and I have needed this capability so far. 2 Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2012 Author Share Posted October 13, 2012 Ok, just tried that and it complains with the message "Field must be in fieldgroup context before its context can be saved" yet I thought I had added the title field to the fieldgroup already in line 156. (Code I'm working on is here.) Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2012 Author Share Posted October 13, 2012 ...but only you and I have needed this capability so far. Can I ask for something that no-one (well probably no-one) has asked for yet from PW? Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2012 Share Posted October 13, 2012 Sorry there was a typo in my previous code, and I'm pretty sure that's why it didn't work. You want to use getField() rather than get(). $ls_fieldgroup->getField('title', true); The reason for this is that getField() can return a field in context but get() can't (as it only has 1 argument). 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2012 Author Share Posted October 13, 2012 Yes, that did it, thank-you Ryan! That will make installing the URL shortening module much easier. 1 Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2012 Share Posted October 13, 2012 Can I ask for something that no-one (well probably no-one) has asked for yet from PW? Of course -- nobody ever needs to ask if they can ask. Just ask. Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2012 Author Share Posted October 13, 2012 Is there any way to extend the fields in a module's uninstall field wrapper? I'd like to add an option that only applies to uninstalling the module (in this case, should the module also remove all the shortlink pages/fields/templates that were created.) I know I could just make this a normal module configuration checkbox field, but as it is only applicable at uninstall time, it would seem logical to have it within the uninstall field wrapper. Link to comment Share on other sites More sharing options...
ryan Posted October 13, 2012 Share Posted October 13, 2012 Hmm that's a good question, I've not tried to do that before. Though as a general thing, I think it's good for a module to uninstall everything that it installs. Is there a situation where you think someone uninstalling would want to leave those things there? If there is, then it might be better to take the strategy of uninstalling nothing and just include manual uninstall documentation. But if you think it's worthwhile to have something more, I'll keep thinking here. Right now I don't know how we'd set this up exactly, but I'm sure there's a way. 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 13, 2012 Author Share Posted October 13, 2012 This is in no way urgent. With the link shortener I just wanted to give the administrator the option of conveniently removing all the short-links at uninstall time in case there were a lot of them. However, it would be pretty easy for them just to delete the parent page containing the links anyway. 1 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