Jump to content

Control Inputfield visibility in just one fieldgroup's context


netcarver
 Share

Recommended Posts

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 by netcarver
Link to comment
Share on other sites

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. :)

  • Like 2
Link to comment
Share on other sites

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).

  • Like 1
Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...