Jump to content

Using InputfieldPage in api


Entil`zha
 Share

Recommended Posts

Hi,

Could someone help me InputfieldPage. I'm creating a custom admin module and I want to create form that has one Page reference field. I've managed to create the field but when loading the page it gives me error that this field hasn't been configured. Basically it's a ghost field that doesn't exist but I also tested to create and configure field with same name but no help.

So if someone could help me how to specify necessary information for field and also how to show selected pages.

Here's code:

		$form = $this->modules->get('InputfieldForm');
		$form->action = "{$this->page->url}savegroup?id={$g->id}";
		$form->method = "post";
		
		$field = $this->modules->get("InputfieldText");
		$field->name = "groupname";
		$field->label = __("Ryhmän nimi");
		if ($g->groupname) {
			$field->value = $g->groupname;
		}
		$form->add($field);
		
		$field = $this->modules->get("InputfieldPage");
		$field->name = "members";
		$field->label = __("Members");		
		$form->add($field);

 

Link to comment
Share on other sites

Maybe you need an InputfieldAsmSelect populated with the pages you want?

Here's one that allows textformatter selection for text fields

$f = $this->modules->get('InputfieldAsmSelect');
$f->setAttribute('name', 'textformatters');
$f->label = $this->_('Text formatters (for file descriptions)');
$f->description = $this->_('Select one or more text formatters (and their order) that will be applied to the file description when output formatting is active. The HTML Entity Encoder is recommended as a minimum.'); 

foreach($this->wire('modules') as $module) {
    $className = $module->className();
    if(strpos($className, 'Textformatter') !== 0) continue; 
    $info = $this->wire('modules')->getModuleInfo($module); 
    $f->addOption($className, "$info[title]");
}

You'd get the pages you want with $this->pages->find(selector) and build your options with addOption() or addOptions() methods

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