Jump to content

Templates dropdown as a select field


pogidude
 Share

Recommended Posts

I'm updating this module.

and I'm trying to add a field/form like in the screenshot. post-1067-0-81922000-1371186861_thumb.pn

Where the admin can select a page that users will be able to add to (left side) and what templates they can add (right side). This should work like a repeater field.

I can build the first part. I'm not very sure how to build the second part since the second field, in the repeater, is a select field of templates. Oh yeah, I'm not even sure how to programmatically build a repeater field.

Here is my code:

public function ___install() {

        ....

	//add role_add_children_pages
	$field = new Field();
	$field->name = 'role_add_children_pages';
	$field->label = 'Pages users with this role may add to';
	$field->labelFieldName = 'path';
	$field->type = wire('modules')->get('FieldtypeRepeater');
        
        //now what??
	//$field->type = 

	$field->description =
		'In order to add to child pages, this role must have page-edit permission or the user must also have another role with page-edit permission.';
}


or if there's a module that uses repeater fields in a similar way I can take a look at that.

Link to comment
Share on other sites

I'm pretty sure that a Repeater can't be used for Inputfield forms outside of ProcessPageEdit. It's sufficiently complex enough, and tied into its storage engine (pages) that it can't be used for other forms. As a result, if you need something similar, you might have to bundle your own input type into an InputfieldMarkup or something. 

Link to comment
Share on other sites

Thanks ryan. Anyway, let's forget about the repeater field for now. My real question is, how do I create a select box or something similar that allows a user to select page templates.. as in my original question

I'll use an example of the Checkboxes inputfield, but it could also InputfieldAsmSelect or InputfieldSelectMultiple, etc. This is in the context of a ConfigurableModule's getModuleConfigInputfields() method, though it would be the same elsewhere. 

public static function getModuleConfigInputfields(array $data) {
  $form = new InputfieldWrapper();
  if(!isset($data['templateIDs'])) $data['templateIDs'] = array();
  $f = wire('modules')->get('InputfieldCheckboxes');
  $f->attr('name', 'templateIDs');
  foreach(wire('templates') as $template) {
    $f->addOption($template->id, $template->name); 
  }
  $f->attr('value', $data['templateIDs']);
  $form->add($f); 
  return $form;
} 
Link to comment
Share on other sites

Is it possible to create a Templates select box field in ProcessPageEdit?

That's essentially what I posted above, though in a different context (module config rather than ProcessPageEdit). If you wanted one in ProcessPageEdit, you'd probably want to create a new Fieldtype for it. Actually, just checked and it looks like Hani already has

  • Like 1
Link to comment
Share on other sites

That's essentially what I posted above, though in a different context (module config rather than ProcessPageEdit). If you wanted one in ProcessPageEdit, you'd probably want to create a new Fieldtype for it. Actually, just checked and it looks like Hani already has

hmmmm.. now I'm getting it.. thanks! how do I check for module dependencies in my module? I'd like to notify user to install Hani's module if it's not yet installed.

Link to comment
Share on other sites

just thought to tell you Ryan that everything *clicked* today. basically, what you were saying was, "create a Template Select input field module and use that for my other module" right? of course I don't have to do that anymore with Hani's module + dependencies but this definitely was lightbulb moment for me :D thanks

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