Jump to content

InputfieldPage: Not fully configured / currently nonfunctional


Harmster
 Share

Recommended Posts

Hey,

I am trying to create a template with a field with the type page from a module using the API.

This is some of the code I use to generate the field and the template.

The field

$mvc_register_field = $this->fields->get('mvc_register_page_id');
if(!$mvc_register_field->id){
   $mvc_register_field = new Field();
   $mvc_register_field->name = 'mvc_register_page_id';
   $mvc_register_field->label = 'MVC Register Page ID';
   $mvc_register_field->description = 'Checkbox that enables MVC for a page';
   $mvc_register_field->type = 'FieldtypePage';
   $mvc_register_field->save();
}

And the template

if(!$this->templates->mvc_register){
   $t = new Template();
   $t->name = 'mvc_register';
   $fieldgroup = $this->fieldgroups->get($t->name);
   if(!$fieldgroup->id){
      $fieldgroup = new Fieldgroup();
      $fieldgroup->name = $t->name;
      $fieldgroup->add($this->fields->get('mvc_register_page_id'));
      $fieldgroup->save(); 
   }
   $t->fieldgroup = $fieldgroup;
   $t->roles = array($this->roles->get('superuser')->id);
   $t->save();
}

And this is how i try to create a page

$controller_registry = new Page();
$controller_registry->template = $this->templates->get('mvc_register');
$controller_registry->parent = $this->pages->get("name=" . self::PAGE_NAME);
$controller_registry->title = $controller_name;
$controller_registry->name = $controller_name;
$controller_registry->mvc_register_page_id = $this->pages->get('url=page_url');
$controller_registry->save();

Which gives me this error:

InputfieldPage: Not fully configured / currently nonfunctional (mvc_register_page_id)

How do I resolve this?

Link to comment
Share on other sites

In a bit of a rush, so not sure if this is definitely right, but saw your question and thought this might help:

https://github.com/adrianbj/ProcessPageFieldSelectCreator/blob/master/ProcessPageFieldSelectCreator.module#L377

It seems like you are missing some config options in your page field, possibly the parent_id and/or template_id - these are what you would set on the Input tab when creating a page field through the admin.

Hope that helps. 

Link to comment
Share on other sites

Ok that sounds fair, however I have no idea what values I should put there? 

Page Inputfileds have to have directions on what pages should be selectable. Only you can know what pages you want to be selectable. The most common scenario is all pages having a certain parent. In that case, you'd set the parent_id property to be the ID of the parent page having those children. Another common scenario is all pages using a certain template, in which case template_id would be the property you'd want to set. There are also other options, like findPagesSelector where you specify a selector string to find the pages that should be selectable. If you'd like you can create+configure the field how you want it in Setup > Fields, then view the entry in PhpMyAdmin in table fields column data to see what options it stored. 

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

    • By snck
      Hello,
      in a project I use the multi-instance feature of ProcessWire to get content from another ProcessWire instance which is kind of a "database". I do not modify the external content. For a slider I want to store references to the "database" in an InputfieldPage. To get the available pages I use the following code in my ready.php:
      $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'kub_highlight_artworks') { // Server path to the PW installation $path = '/var/www/vhosts/.../'; // The root URL for the PW installation $url = 'https://.../'; // Create a new ProcessWire instance $db = new ProcessWire($path, $url); $event->return = $db->pages->find("template=artwork, sort=title"); } }); Outputting and selecting the external pages works perfectly fine, but unfortunately the selected pages do not get saved when I save the page.
      Can someone point me into the right direction how to make this work? Are there any internal checks whether the page exists in the current instance that prevent saving the values?
      Best,
      Flo
    • By Jason Huck
      I have a Page field with no restrictions on selection, set to use Page Autocomplete. Administrators need to be able to select the home page just like any other. When they type "Home" into the field, the home page appears as an option, but when it is selected, nothing happens.
      There aren't any javascript errors, and other pages can be added as expected. I do notice in the AJAX call to get the menu results there is a query param "id>0" but "Home" does appear in the list, it just can't be selected.
      Page Autocomplete is the only practical UI option due to the large (over 6k and growing) number of pages in the site.
      Has anyone else seen this behavior? Is this a bug or am I missing something in the configuration? This is on PW 2.7.3.
    • By seddass
      Hi all, 
      Hope for a helpful hint and thank you in advance. 
      I am trying to create a form in the frontend with custom markup for the form and the fields. Its all fine, except that I cant find out
      1. how to remove the empty "<option></option>" choice and
      2. I was wandering if there is a smarter way of making one of the options "selected" in page field using select inputfield. 
      Here is my code:
      $newPage = new Page(); $newPage->template = 'my_weather'; $field = $fields->get('temp_units'); $inputfield = $field->getInputfield($newPage); $select = $inputfield->getInputfield(); $options = $select->getOptions(); foreach ($options as $key => $val){       $select->removeOption($key); }              foreach ($options as $key => $val){ $attr = ($val == 'kg') ? array('selected' => 'selected') : null;        $select->addOption($key, $val, $attr); } echo $select->render(); Of course, I could skip render() and output my markup with the options above instead, but it is a quite large form and I prefer to know if this is the right way of getting things done with the API. 
      Thanks!
×
×
  • Create New...