Jump to content

Page Reference field set via API for module configuration


LAPS
 Share

Recommended Posts

I'm developing a module that has a configurable Page Reference field. For this page field, I would like to set some options via API. Here are these options as they are shown in the admin area:

  • Details > Page field value type set to "Multiple pages PageArray".
  • Input > Selectable pages > Template set to "template-name".
  • Input > Selectable pages > Label field set to "Custom format": "{title} {summary}".
  • Set initial values (see below).

In my module file PageSelectionModule.config.php I have:

class PageSelectionModule extends ModuleConfig {

	public function __construct() {

		$this->add(array(

			// Page field: selectedPages
			// Note: By using this code, in the module page I get the error message:
			// "This field needs to be configured before it can be used".
			array(
				'name' => 'selectedPages', 
				'type' => 'page', 
				'label' => $this->_('Selected pages'), 
				'description' => $this->_('Selected pages description).'), 
				'value' => ???, 
				'required' => true,
				'notes' => $this->_('Selected pages notes'),
			)

		)); 
	}
}

My questions are:

  1. How can I set the above page field options via API in the module?
  2. Is the 'value' handled (stored and retrieved) internally by PW?
  3. Where I can find some documentation about all this?
Link to comment
Share on other sites

I'd recommend using Tracy Debugger for two reasons

  1. You have the field settings and field code panels where you can inspect your necessary properties
  2. Tracy has many many examples of how you can add fields to your module's config screen
$f = $this->wire('modules')->get("InputfieldAsmSelect");
$f->attr('name', 'hideDebugBarFrontendTemplates');
$f->label = __('No debug bar in selected frontend templates', __FILE__);
$f->description = __('Disable the debug bar on pages with the selected templates.', __FILE__);
$f->columnWidth = 50;
foreach($this->wire('templates') as $t) {
	$f->addOption($t->id, $t->name);
}
if($data['hideDebugBarFrontendTemplates']) $f->attr('value', $data['hideDebugBarFrontendTemplates']);
$fieldset->add($f);

 

Link to comment
Share on other sites

@bernhard, thank you for remembering me to use Tracy Debugger. ?

Assuming the Tracy field settings and field code panels that you mentioned are in the "Request info" tab, when I expand the "Field List & Values" link in it, then it doesn't list the Page Reference field that in my case is not working (the field shows the error message above).

In fact, only 'title' and 'process' fields are shown.

Link to comment
Share on other sites

By using an array to define module configuration (PW new module configuration) I partly solved the issue of configuring the Page Reference field because data is not saved:

array(
  'name' => 'selectedPages', 
  'type' => 'page', 
  'label' => $this->_('Selected pages'), 
  'description' => $this->_('Selected pages description).'), 
  'inputfield' => 'InputfieldCheckboxes',
  'derefAsPage' => 0,
  'collapsed' => 0,
  'optionColumns' => 0,
  'labelFieldName' => '.',
  'labelFieldFormat' => '{name}',
  'findPagesSelector' => 'template=named-template, include=all',
  'allowUnpub' => true,
  'required' => true,
  'defaultValue' => 1985,
  'notes' => $this->_('Selected pages notes'),

  // I tryed to set value to '', [] and $this->selectedPages without success
  'value' => ???,

)

How should I configure the page checkboxes field to store data submitted from the module page?

 


Update: I found a possible solution here.

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