Jump to content

Reciprocal Data


ptjedi
 Share

Recommended Posts

Good evening,

I am trying to build a system that relates two pages (using a Page field) but assures that the related page also relates to the current page we're editing. Like if we were talking about synonyms.

Does anyone have a clue on how to achieve this?

Thanks!

Link to comment
Share on other sites

Not sure if I understand right.

Edit:

If page field is limited to one page max you could also do this

if($page->related->related === $page){
// related page has this page also referenced
} else {
// it's not
}

Edit2:

corrected a previous example if multiple page field with better example

if(count($page->related)){
foreach($page->related as $rel){
       // check recursively if one of the related pages has this page in it's related pages 
	if($rel->related->has($page)){ 
		echo "<li>$rel->title</li>";// related page has this page also referenced
	} else {
		// it's not
	}
}
}
  • Like 2
Link to comment
Share on other sites

When you use a page field you can always relate the pages both ways. Only the way you call them is different.

You call B from A like this:

$page->pagefield

and A from B like this:

$pages->get('pagefield=$page')

where A is the page that has the page fieldType

  • Like 1
Link to comment
Share on other sites

Thanks you both. I imagined something like that, and it will come handy when I am setting the template files for it.

However my question goes toward something that identifies in the backoffice that some page has been linked from another and therefore, holds a link to that page. Have any idea if this is feasable without touching core code?

Link to comment
Share on other sites

Actually I'm recently working on a module that lists links to selected pages on a page field when on edit page after saving. Doing something else would be quite easy with one of the above methods. I'll have to pick it up see what I can share.

Link to comment
Share on other sites

I quickly looked into it and created an additional hook for what you might after. There's my other already created ones you can also test and comment it if not needed.

It's a snippet I just posted here https://gist.github.com/2878361

Uncomment unwanted hooks int he init() method of the module.

The third hook...

$this->addHookAfter("InputfieldPageListSelect::render", $this, "findRelated");

does look for any pages that has the current edited page selected in a page select field. You can specify what field you want to attach it in the function findRelated(): $field_filter = "select_architect";

Let me know if it works for you.

  • Like 1
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...