Jump to content


Photo

Page Fieldtype two way relation

relations page fieldtype

  • Please log in to reply
14 replies to this topic

#1 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 17 March 2012 - 03:35 PM

So I started on the project I spoke of earlier and already got most things signed off. With the search function and some video's I was able to build the site. I got a couple of things to work on like a contactform. I guess that shouldn't be to hard. PW seems to be very intuitive and it feels very mature and well thought of.

I used the Page Fieldtype (thanks Diogo and others from my first thread) to link pages to each other and it works like a charm. The thing is I would to see the relation two ways in the backend.

Example: I link page A to page B1 and page B2. When I edit page A in the backend I see B1 and B2. But I'd like to see page A when I edit page B1 (or B2).

I tried to put the same field in the other template, but that (perhaps obviously) did not work.

What kind of field do I need to put in the template? Is this possible?

Thanks!
work will always be the curse of the drinking classes...

#2 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 658

  • LocationChester, England

Posted 17 March 2012 - 04:04 PM

My first question is why would you need to do that (I originally wanted to do the same thing)? You can already use selectors via the API in templates to find pages in the other direction.

For example, on one site I link news to companies, so the Pagefield for the company is available in the news template (call that field related_company) and I can therefore show some company info with that news article.

On the company page via the company template, I can still pull news articles for that company (the reverse of the above) by using something like $news = $pages->find('template=news, related_company=$page');

I would say that unless you have a real need to do this, try not to over complicate it.

Of course, your scenario could be very different :)

#3 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 17 March 2012 - 05:50 PM

Thanks! That's exactly how I did it in both templates. I thought for the user it would be nice to see in the administration part if a page is linked to another. Therefor the user won't have to look in the other page or on the actual website itself to determine wether any pages are linked.

I got an employee A who is linked to a service. Also employee B is linked to that service. On the service page (in the administration part) I thought it would be handy to see which employees are linked. Even to de-link them. If you have any thoughts if this sounds too much I would be glad to hear that
work will always be the curse of the drinking classes...

#4 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,530 posts
  • 858

  • LocationVihti, Finland

Posted 18 March 2012 - 01:15 AM

Currently there is no such a feature, but I agree that it would be a useful feature to have. It shouldn't be too difficult module to build. Maybe a fieldtype that just shows all relations for that page and where they are defined.

#5 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 18 March 2012 - 04:30 AM

Thanks for clarifying Apeisa. It isn't that big of a feature, but it would be nice.
work will always be the curse of the drinking classes...

#6 Pete

Pete

    Administrator

  • Administrators
  • 1,756 posts
  • 658

  • LocationChester, England

Posted 18 March 2012 - 04:34 AM

I think you're on the right track Antti.

The first time I thought about it, back when I was very new to PW, I thought that it should save the relationships both ways. Obviously to de-link the pages this makes it a bit more complicated, plus adds unnecessary clutter to the database (you're saving the relationship twice).

Your module idea sounds good and I don't think it would be much more work on top of the "view relationships" to have a button that removes the relationship, so you can do it from either end.

Having said "I don't think it would be much more work" I don't have time to look at it myself, but I agree it would be an interesting one to look at for the future. Could even be a useful core addition.

I think the only concern I have is to keep it from being confusing for the user, as if they can see page relationships but can't add relationships this might become confusing. Again, you could theoretically add functionality to create more relationships from such a module, but then you're really blurring the lines around which page the data is actually stored against.

I like to over-complicate things - maybe just viewing the relationships would be fine :D

#7 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 18 March 2012 - 06:58 AM

It depends on how you present the information. If you can see the relations, but don't have any clickable objects, let's say, just a diagram, I think it should be clear enough. I haven't got any clue on how to build this, but after this project I haven't got any new one yet. So it might be worth exploring this further.
work will always be the curse of the drinking classes...

#8 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 18 March 2012 - 08:43 AM

A pre-made module for this on the admin wouldn't know what field(s) might be referencing the $page, so it would need to locate all the Page fieldtypes, and perform a check on all of them: "field1|field2|field3=$page". I prefer to view these kind of relations on the front-end of my site (where I can give them a known field context), so my template for the pages in the relation will usually have something like this:

echo $pages->find("field1=$page")->render();

If the page isn't part of the front-end site, then I'll remove view access from its template. Or if it is part of the front-end, but I don't want to show the relations, then this:

if($page->editable()) echo $pages->find("field1=$page")->render();

Though I almost always integrate these relation-revealing pages into the site structure, as it's rare that this information doesn't have some value to the site's users too. This is an example of one that locates all pages referencing it in a field called 'country':

http://www.tripsite....ntries/croatia/

#9 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 19 March 2012 - 03:23 AM

Thanks Ryan, for now I will look up the relation in the front-end. It does make sense indeed because you can see the context.
work will always be the curse of the drinking classes...

#10 isellsoap

isellsoap

    Jr. Member

  • Members
  • PipPip
  • 22 posts
  • 6

  • LocationDresden, Germany

Posted 01 March 2013 - 05:22 AM

Just wanted to ask: are there any new developments regarding arjen’s request or does one still have to use the »front-end approach«? Thanks.



#11 ryan

ryan

    Hero Member

  • Administrators
  • 5,780 posts
  • 3125

  • LocationAtlanta, GA

Posted 02 March 2013 - 07:05 AM

Just wanted to ask: are there any new developments regarding arjen’s request or does one still have to use the »front-end approach«? Thanks.

 

This feature is not currently on the roadmap, but I would guess someone will develop this as a module at some point. When it comes to core stuff, we really try and focus on stuff that would be used most of the time, and leave occasional use things mostly to modules.



#12 Soma

Soma

    Hero Member

  • Moderators
  • 3,217 posts
  • 1763

  • LocationSH, Switzerland

Posted 02 March 2013 - 07:47 AM

I have created a sample module that does mapping two page fields against each others

 

As per http://processwire.c...r-one-possible/

 

https://gist.github....matonic/4335296

 

I also have a rough module that adds links to the pages linked after saving, but it's not something I can share.

 

But looks like it's not what you actually ask for, but anyway all is possible.


@somartist | modules created | support me, flattr my work flattr.com


#13 nik

nik

    Sr. Member

  • Members
  • PipPipPipPip
  • 204 posts
  • 331

  • LocationTampere, Finland

Posted 07 March 2013 - 02:56 PM

@arjen, @isellsoap: I'm not quite sure if it became what you were thinking of, but this conversation was the inspiration behind this: http://processwire.c...ereferencestab/

 

At least it's something you could use as a base for something more if it's only half way there at the moment.


My modules: Selector Test | After Save Actions | References Tab ~ Other: Tests for ProcessWire core (work in progress)


#14 isellsoap

isellsoap

    Jr. Member

  • Members
  • PipPip
  • 22 posts
  • 6

  • LocationDresden, Germany

Posted 08 March 2013 - 03:13 AM

@nik that looks really good, thanks a lot! :)



#15 arjen

arjen

    Sr. Member

  • Members
  • PipPipPipPip
  • 340 posts
  • 125

  • LocationHoogeveen, The Netherlands

Posted 08 March 2013 - 03:57 AM

Thanks nik! Really helpful as usual. The client loves it :)


work will always be the curse of the drinking classes...





Also tagged with one or more of these keywords: relations, page fieldtype

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users