Hi,

I'm pretty new to Drupal and am testing out the Subscriptions module with Pathauto enabled.

The following are the Subscriptions module display settings:
Node form position: Fieldset in Subscriptions interface block (below the comments).
Node form visibility: Display only a Subscribe link that makes the fieldset visible.

When I go to a page on my website that has a URL alias created by pathauto (e.g. http://example.com/testSection/20) and click on the "Subscribe" link, the URL it links to refers to something like the following: http://example.com/node/20/subscribe#subscribe . Does anybody know of a way to automatically specify the creation of aliases like http://example.com/testSection/20/subscribe#subscribe?

Thanks in advance.

P.S. Sorry if this is the wrong place to post my question so please correct me if it is.

Comments

greggles’s picture

Project: Pathauto » Subscriptions
Version: 5.x-2.3 » 5.x-2.x-dev

If subscriptions uses node/20 instead of testSection/20 then that is a bug in Subscriptions.

I guess that it is not using l() or url() to generate the links, but maybe it's something else.

salvis’s picture

We're using

        array('subscriptions-subscribe' => array(
          'href' => $_GET['q'] .'/subscribe',
          'title' => t('Subscribe'),
          'fragment' => 'subscribe',
          'attributes' => array('title' => t('Receive notifications about changes and/or comments to this page (and possibly similar pages).')),
        ));

to construct the link (in hook_link()). What would be the proper way do do this?

Also, we're using arg(0) == 'node' && is_numeric(arg(1)) && arg(2) != 'subscribe' to decide whether to show the link at all. I'm surprised that this works with pathauto, but apparently it does...

Furthermore, we're using arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'subscribe' to decide whether to show the node subscriptions form.

Can this work?

greggles’s picture

$_GET['q'] .'/subscribe'

Should ideally be:

check_url(url($_GET['q'] .'/subscribe'))

And yes, while the public url is the alias created by pathauto the internal values for arg() and $_GET['q'] are "fixed" to be the internal path.

salvis’s picture

Status: Active » Postponed (maintainer needs more info)

Thanks, greggles!

new_B: Can you try this and report back? The function is subscriptions_ui_link() in subscriptions_ui.module, line 89.

I'm debating whether the links in the notifications should be translated as well... Opinions?

new_B’s picture

Hi salvis,

I tried greggles' fix as suggested but the base URL (e.g. http://www.example.com) is missing. I get a broken link: http://node/95/subscribe#subscribe .

Regarding translating the links in the notifications, if you mean links to pages that have been subscribed to, I believe they already use the pathauto generated URL aliases.

Thanks.

greggles’s picture

See http://api.drupal.org/api/function/url

To make it absolutely you will need to call url with the second argument array('absolute' => TRUE).

salvis’s picture

@new_B: For links on the site (to the site) you shouldn't need the http://www.example.com part. Otherwise use

check_url(url($_GET['q'] .'/subscribe', array('absolute' => TRUE)))

as greggles points out.

links in notifications = the link in the email message that points back to the node

salvis’s picture

Status: Postponed (maintainer needs more info) » Active

@greggles: new_B is right:

url($_GET['q'] .'/subscribe')

produces a string with a leading slash, which ends up being passed through l(), which prepends a second slash, resulting in a broken link.

Do you know why l() is so dumb?

greggles’s picture

I think I'm confused about this issue a bit and I'm quite sorry for that.

If you want your value from url to be used directly then I think you could use the "alias" option in your hook_link (it's not documented in hook_link so it may not work but it is documented on the page for l().

But I think I led you down the wrong path initially :( Part of the answer to the original problem is that there is no alias for "node/20/subscriptions" and there likely shouldn't be. Creating all those aliases is a performance problem and a UI problem. It is documented as a feature request to Pathauto in #217707: Multiple patterns/paths for one entity or could also be done in Subscriptions by implementing some Pathauto API. So, I think this is duplicate unless you want to provide the aliasing for the "node/20/subscriptions" path yourself.

salvis’s picture

Hmm, now I'm confused, too...

It all started out with a path like node/20. According to new_B, Pathauto modifies this into testSection/20 on his site, so that's what he sees in his browser's address bar.

Nonetheless, $_GET['q'] returns 'node/20', and Subscriptions used this to add a 'Subscribe' link to the node, which then pointed to node/20/subscribe#subscribe.

When a user clicked on the link, Drupal served node/20, ignoring the 'subscribe' part, but Subscriptions picked it up and added the node subscriptions interface to the node view. This is the inheritance rule of the menu system (http://drupal.org/node/109584).

Now, new_B would like to see testSection/20/subscribe#subscribe rather than node/20/subscribe#subscribe, which I think is reasonable.

Yes, there is no testSection/20/subscribe alias, but shouldn't Pathauto pick up the testSection/20 part and convert that back to node/20, which would then give node/20/subscribe again? Or does Pathauto not support inheritance? Shouldn't it?

I've committed a patch to implement #3 (and correct the double leading slash problem) yesterday, it's available in the current -dev snapshots.

I'm not sure I can get up to speed with Pathauto quickly enough to test this myself — if anyone can give it a try within the next few hours, then please let me know asap (and follow up, of course), otherwise I'll make a new beta release with this in place. I don't think it should hurt, it just may not help...

salvis’s picture

@greggles: Please see #354621: Subscribe Link renders incorrectly with sub-folder install...

Do you have any idea what is happening?

greggles’s picture

Not entirely. I think that the code shouldn't have "url()" in it since Drupal does that elsewhere.

And I think that perhaps I totally misunderstood what this issue was about in the first place and that maybe this was just a request for something like #217707: Multiple patterns/paths for one entity.

salvis’s picture

No, I don't think this is about #217707: Multiple patterns/paths for one entity.

Subscriptions appends '/subscribe' to the node path to show the subscriptions node subform. This works fine with paths such as node/NID, but Pathauto paths such as what-this-is-all-about revert to node/NID/subscribe because of $_GET['q'] .'/subscribe'.

I thought you said in #3 that I could get what-this-is-all-about/subscribe by using url(), but apparently this causes new and more serious problems.

Is there a reliable (and reasonably easy) way to accommodate Pathauto? Otherwise I'll just revert this change.

greggles’s picture

I thought you said in #3 that I could get what-this-is-all-about/subscribe by using url(), but apparently this causes new and more serious problems.

I'm definitely quite confused about the proper thing to do here and was giving advice without looking into the real issues deeply enough. I would suggest that you do revert the change.

salvis’s picture

Category: support » feature
Status: Active » Closed (won't fix)

Ok, reverted in the snapshots. Thanks.