Jump to content

Help with multisite tagging system - ASMSelect selectable pages and Multisite setup


Jimmie Bragdon
 Share

Recommended Posts

Wondering if anyone can help me get past a sticking point.  

I'm setting up a Processwire instance in a multiple site setup (using Soma's multisite) to run several related websites.  I am getting stuck on the tagging system that I am using (adapted from a standalone PW site I'm running).  I have the tags themselves set up as Pages, and the Tags field on the related pages is and ASMselect field that populates based on the pages underneath /tags/ in the tree.  This system works fine on the standalone site.

Where I am running into issues, is with trying to use them with the multisite setup.  Specifically, choosing the proper subset of pages for tags on the ASMselect input tab.  I want to choose only the tag pages for the site in question.  

My tree is laid out like this:

Multisite / 

          | site1.com

               | subsections

          | site2.com

               | subsections

          | Tags

               | site1.com

                    | tagA

                    | tagB

               | site2.com

                     | tagC

So far, the best I've been able to do is to use  'parent.has_parent=/tags/' in the Custom Find or Selector String portion of the Selectable Pages section of the input.  This gives me the options of choosing tagA, tagB, or tagC on a page under site1.com.  What I'd like to find is a selector that allows me to only see tagA, tagB as options from a page under site1.com and only tagC on a page under site2.com.

Elsewhere in my php templates, I'm using $page->rootParent->title to set the proper scope and URLs for things, but I have not found a way to get that to work in this field input setup.  I am trying to avoid creating specific fields and templates for each site, as unified templates were part of the purpose of going with a multisite install.

 

Thanks in advance for any ideas.

Link to comment
Share on other sites

Short answer: this sounds like a use case for the "Custom PHP code" option of the Page field you're storing tag references into. This way you can do a lot more than with just selectors.

Link to comment
Share on other sites

Thanks, @teppo, I looked into that.

I went with the following:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  $page = $event->arguments('page');
  $siteName = $page->rootParent->title;
  $parentSelector = 'parent=/tags/'.$siteName.'/';
  if($event->object->hasField == 'Tags') {
    $event->return = $event->pages->find($parentSelector);
  }
});

This selects the right tags now in the ASMselect input field.  I did have to abandon letting new Pages be created from the template, as it was not placing them in the correct place in the tree (It was dropping them in /tags/ instead of /tags/sitename/) and had to remove the required parent (previously set to /tags/) as it wasn't detecting the proper parent on the tags, so wouldn't save them to the page in question.

But at the cost of manually creating the tag pages, the rest of the solution seems to work!

Link to comment
Share on other sites

13 hours ago, Jimmie Bragdon said:

I did have to abandon letting new Pages be created from the template, as it was not placing them in the correct place in the tree (It was dropping them in /tags/ instead of /tags/sitename/) and had to remove the required parent (previously set to /tags/) as it wasn't detecting the proper parent on the tags, so wouldn't save them to the page in question.

You could try out the idea for "Dynamic parent and/or template for pages created from the inputfield" outlined in this post:

 

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