Jump to content

InputfieldPage and multi-instance support


snck
 Share

Recommended Posts

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

Link to comment
Share on other sites

8 hours ago, snck said:

but unfortunately the selected pages do not get saved when I save the page.

Could you please show us your code for this bit?

Secondly, it is not clear whether you want to store pages from one instance in another instance. If that's the case, maybe this applies to you?

Quote

Be careful not to load objects from one instance and save them to another. Loaded objects are going to be connected with the instance they were loaded from. They might have a database ID unique to that installation, and so on. If you need to copy/move object data from one instance to save to another, convert to basic types and re-create the objects. For instance, if copying an image from one instance to another, do a $page->images->add($filename); rather than trying to add the Pagefile object from another installation.

https://processwire.com/blog/posts/multi-instance-pw3/#pitfalls-and-considerations

  • Like 2
Link to comment
Share on other sites

On 8/17/2020 at 9:15 PM, kongondo said:

Could you please show us your code for this bit?

Secondly, it is not clear whether you want to store pages from one instance in another instance. If that's the case, maybe this applies to you?

https://processwire.com/blog/posts/multi-instance-pw3/#pitfalls-and-considerations

There is no code for it. The pages are edited in the backend by editors using the normal page edit dialogue.

I do not try to store pages from one instance in the other, at least this is what I was thinking. From my understanding InputfieldPage is just storing references to pages which is what I want to achieve: Store references to pages of instance1 in a page on instance2.

Maybe this clears it up?

 

Link to comment
Share on other sites

4 hours ago, snck said:

Maybe this clears it up?

Sort of 😄  

4 hours ago, snck said:

Store references to pages of instance1 in a page on instance2.

This is still confusing. When you say store, do you mean store in memory? I am assuming that is what you mean since you said you are not doing any saving in your code. On the other hand, if you mean saving (i.e., database-storage-sort-of-saving) references to pages of instance1 in a page on instance2, then I am not sure how you can achieve that without having the pages in instance1 also present in instance2. You are using a Page Field and they cannot store external pages. Those pages must exist on the site the Page Field is present in.

4 hours ago, snck said:

From my understanding InputfieldPage is just storing references to pages which is what I want to achieve:

Again, maybe I am misunderstanding something, but InputfieldPage (all inputfields, in fact) do not store anything, if by store you mean save. Storage is achieved via Fieldtypes. 

Am I on the right track? :-) 

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

×
×
  • Create New...