Getting the most relevent URL for a node

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting the most relevent URL for a node

McBride, Ian S.
This afternoon I added a bit of functionality to the module where we keep our custom Monster Menus hacks and thought I'd share what I did. It's attached as a diff to this email to show just the relevant bits, but I'd happily provide it in another format if that'd help anyone. The basic problem that I'm trying to solve is that when you have MM enabled and use url('node/123') you will get back the URL of the page where the node was first added.

Consider a node with nid 123 that was first created on page 400 and later added to page 300 (the numbers are their MM tree ids). It will have a mm_catlist of:

array(
  0 => 400,
  1 => 300,
);

And url('node/123') will return the equivalent of 'mm/400/node/123' always. This is due to some decision made in mm_url_rewrite_outbound() and mm_parse_args() that I confess I wasn't able to figure out.

If node 123 happens to be a profile of a faculty member who teaches in the English department (page 400) and the History department (page 300) and you're viewing a teaser of their profile in the History department, the value of $node_url in node.tpl.php will go to the English department, since that's the page where the node was first created and the zeroth index in $mm_catlist.

To get around this, I created this function:

/**
 * If a node appears on multiple pages, find the page closest to the one currently being viewed.
 *
 * @param object $node
 *   The node object, as returned by node_load().
 * @return string
 *   A URL in the form mm/MMTID/node/NID or just node/NID if no corresponding page was found.
 */
function middlebury_monster_menus_get_closest_url($node) {
  $url = 'node/' . $node->nid;

  // When a node appears on multiple pages, make sure that its $node_url value is set to the current page.
  if (!empty($node->mm_catlist) && count($node->mm_catlist) > 1) {
    $mmtids = array_keys($node->mm_catlist);
    $mmtid = array_search(arg(1), $mmtids);
    if ($mmtid !== FALSE) {
      $url = 'mm/' . $mmtids[$mmtid] . '/node/' . $node->nid;
    }
    else {
      foreach ($mmtids as $mmtid) {
        $parents = mm_content_get_parents($mmtid);
        $parent = array_search(arg(1), $parents);
        if ($parent !== FALSE) {
          $url = 'mm/' . $mmtid . '/node/' . $node->nid;
        }
      }
    }
  }

  return $url;
}

This looks at the current page's mmtid of the page that you're viewing and tries to determine which of the pages the nodes appears on is in that section of the site hierarchy. This approach has some drawbacks: it relies on arg(1), which makes caching the value difficult, and it (sometimes) requires an extra database (or cache) operation through mm_content_get_parents(). However, I was able to use it in a preprocess_node() function to make sure that $node_url is the desired value.

I also wrote two new field handlers for Views which extend the default "Content: Title" and "Content: Link" fields to be MM-aware.

Your feedback on this approach is welcome.



Ian McBride
Web Technologies & Services
Middlebury College
[hidden email]

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=721144
or send a blank email to [hidden email]

mm_node_url.diff (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

grahamtk
Hi Ian.
I also have problems with multiple pages for a node.

Our use case is a bit different though:
We want to show a node on multiple pages, but it seems it redirects to the
shortest path, not to the first page it was created on. I created a node
here:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects/ams/node/25124

I also added this page to the list of pages for this node:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects
and this page:
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter

the two last pages are a list of summaries ( teasers) in both cases the node
is displayed at this location:
which was added last. the only mm related difference in these locations I
see is that it has a shorter path. does that play a role?
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter/node/25124

Also - in this case I dont see that there could be a logic applied that
would result in our preferred location. ( our preffered location is in this
case the longest path, but this could vary. ) I think a way to define "main
location" would be the only solution in our case - meaning a radio input on
the "add page" form of the node settings.

Any thoughts on our predicament is welcome!
Best regards,
Øyvind



--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Getting-the-most-relevent-URL-for-a-node-tp7573147p7573154.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=722947
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

grahamtk
This post has NOT been accepted by the mailing list yet.
In reply to this post by McBride, Ian S.
Hi Ian.
I also have problems with multiple pages for a node.

Our use case is a bit different though:
We want to show a node on multiple pages, but it seems it redirects to the shortest path, not to the first page it was created on. I created a node here:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects/ams/node/25124

I also added this page to the list of pages for this node:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects
and this page:
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter

the two last pages are a list of summaries ( teasers) in both cases the node is displayed at this location:
which was added last. the only mm related difference in these locations I see is that it has a shorter path. does that play a role?
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter/node/25124

Also - in this case I dont see that there could be a logic applied that would result in our preferred location. ( our preffered location is in this case the longest path, but this could vary. ) I think a way to define "main location" would be the only solution in our case - meaning a radio input on the "add page" form of the node settings.

Any thoughts on our predicament is welcome!
Best regards,
Øyvind
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

McBride, Ian S.
In reply to this post by McBride, Ian S.
It does seem like there should be a way to define a "canonical URL" for nodes that need to appear in multiple places, for SEO purposes at the very least.

We'll be meeting with our Amherst colleagues later this week and I'll keep this in mind as a (short) discussion topic.



Ian McBride
Web Technologies & Services
Middlebury College
[hidden email]

________________________________________
From: grahamtk <[hidden email]>
Sent: Tuesday, November 24, 2015 7:49 AM
To: Monster Menus Development
Subject: Re: Getting the most relevent URL for a node

Hi Ian.
I also have problems with multiple pages for a node.

Our use case is a bit different though:
We want to show a node on multiple pages, but it seems it redirects to the
shortest path, not to the first page it was created on. I created a node
here:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects/ams/node/25124

I also added this page to the list of pages for this node:
https://www.nmbu.no/en/about-nmbu/faculties/vetbio/departments/vet/departments/prodmed/projects
and this page:
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter

the two last pages are a list of summaries ( teasers) in both cases the node
is displayed at this location:
which was added last. the only mm related difference in these locations I
see is that it has a shorter path. does that play a role?
https://www.nmbu.no/om/fakulteter/vetbio/institutter/vet/institutter/prodmed/forskning/prosjekter/node/25124

Also - in this case I dont see that there could be a logic applied that
would result in our preferred location. ( our preffered location is in this
case the longest path, but this could vary. ) I think a way to define "main
location" would be the only solution in our case - meaning a radio input on
the "add page" form of the node settings.

Any thoughts on our predicament is welcome!
Best regards,
Øyvind



--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Getting-the-most-relevent-URL-for-a-node-tp7573147p7573154.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685439.7e7cbccf9bb225cf8471bffe1cb67503&n=T&l=monster_menus&o=722947
or send a blank email to [hidden email]

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=723028
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

grahamtk
I Would so like to have a international monster menus users group meetup..
:)

Did you discuss this yet?




--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Getting-the-most-relevent-URL-for-a-node-tp7573147p7573157.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=723175
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

grahamtk
This post has NOT been accepted by the mailing list yet.
In reply to this post by McBride, Ian S.
I Would so like to have a international monster menus users group meetup..  :)

Did you discuss this yet?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

Dan Wilga-2
In reply to this post by McBride, Ian S.
No, we haven't discussed that. Are you inviting us to Norway? :-)

On 12/3/15 9:15 AM, grahamtk wrote:
> I Would so like to have a international monster menus users group meetup..
> :)
>
> Did you discuss this yet?
>
>


---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=723177
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SV: Getting the most relevent URL for a node

grahamtk
In reply to this post by McBride, Ian S.

Every monster menus developer and sitebuilder would be very welcome at our campus, I'm sure!
I do however, notice a small feeling that this idea would benefit from involving my colleagues before setting the date and program ;-)

 

BTW,

We are soon to be done with updating our design from this rather dated design to
 

 

This responsive and modern visual expression:

 

 

With monster menus in place as the mega menu it was born to be:

Here is a part of our site that is in English and where the redesign is mostly done:
https://www.nmbu.no/en/about-nmbu/faculties/

 

 

 

Øyvind

 

-----Opprinnelig melding-----
Fra: Dan Wilga [mailto:[hidden email]]
Sendt: 3. desember 2015 15:21
Til: Monster Menus Development <[hidden email]>
Emne: Re: Getting the most relevent URL for a node

 

No, we haven't discussed that. Are you inviting us to Norway? :-)

 

On 12/3/15 9:15 AM, grahamtk wrote:

> I Would so like to have a international monster menus users group meetup..

> :)

> 

> Did you discuss this yet?

> 

> 

 

 

---

You are currently subscribed to monster_menus as: [hidden email].

To unsubscribe click here: http://lists.middlebury.edu/u?id=1410382.5af74b4693b81b84495f479a03f0e1ec&n=T&l=monster_menus&o=723177

or send a blank email to [hidden email]

---

You are currently subscribed to monster_menus as: [hidden email].

To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=723178

(It may be necessary to cut and paste the above URL if the line is broken)

or send a blank email to [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the most relevent URL for a node

McBride, Ian S.
In reply to this post by McBride, Ian S.
Unfortunately, as of yesterday, we have had to postpone the meeting.
________________________________________
From: grahamtk <[hidden email]>
Sent: Thursday, December 3, 2015 9:15 AM
To: Monster Menus Development
Subject: Re: Getting the most relevent URL for a node

I Would so like to have a international monster menus users group meetup..
:)

Did you discuss this yet?




--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Getting-the-most-relevent-URL-for-a-node-tp7573147p7573157.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685439.7e7cbccf9bb225cf8471bffe1cb67503&n=T&l=monster_menus&o=723175
or send a blank email to [hidden email]

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=723179
or send a blank email to [hidden email]
Loading...