Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
right now AddToAny sets the URL for nodes with this code:
$link_url = url('node/' . $node->nid, array('absolute' => 1));
in addtoany.module::_addtoany_create_button()
Add some way to specify the URL format from the Admin UI. Using the token module would be good, but I don't know if you want this as a dependency.
Examples with possible tokens: I'd use [nid]
to get something like http://ao2.it/51 or I could use [shorturl]
if I am using http://drupal.org/project/shorturl
Regards,
Antonio
Comments
Comment #1
micropat CreditAttribution: micropat commentedGreat feature request. The module easily supports custom domains hosted by bit.ly or awe.sm and also custom short URLs via AddToAny's JavaScript API; however, it would be tricky to get custom short URLs to work with the current module version.
For reference:
http://www.addtoany.com/buttons/customize/link_tracking
To demonstrate a non-working example, you'd specify the following in the AddToAny settings panel > Additional options > Additional script:
Problem is, http://example.com/abc123 needs to be a variable for each short URL.
Also note that one important aspect about using AddToAny's config above is that AddToAny will only enable shortening for services where short URLs are appropriate. For instance, Twitter & Facebook, but not Digg or Google Bookmarks. So I'd advise against replacing $link_url.
Essentially, the settings panel's Additional script box would need to support some kind of 'template variables' or token.
Token module: I'd usually say let's veto a dependency, but it appears that the Token module made it upstream to Drupal 7, so I don't mind using it if it's standard use, efficient, and makes sense.
Any thoughts on a patch or best practices for this kind of thing?
Comment #2
ao2 CreditAttribution: ao2 commentedSo if I get it right, the url in
a2a_config.track_links_key
will be used only when needed by the given service?Btw, enabling tokens in the Additional script field is not too hard:
This allows us, to have somenthing like the following properly replaced:
If that looks right I can send a proper git am friendly patch.
Thanks,
Antonio
Comment #3
ressa CreditAttribution: ressa commentedIs it possible to use the original Drupal URLs, like example.com/node/1027978, and would it be hard to set up?
Comment #4
izmeez CreditAttribution: izmeez commented+1 to the question in Comment #3, how to configure addtoany to use a short Drupal url, http://example.com/node/12345
Comment #5
ao2 CreditAttribution: ao2 commentedwith the patch above you just use
a2a_config.track_links_key = '[site-url]/node/[nid]';
in the last snippet.Please report if that works for you.
Thanks,
Antonio
Comment #6
IWasBornToWin CreditAttribution: IWasBornToWin commentedI just downloaded version 7. Do I need to go somewhere in the module code in order to use a custom url?
Comment #7
enginpost CreditAttribution: enginpost commentedI am working with Drupal 8, but I think this could work for Drupal 7 too. This worked for me...
I added the contrib metatag module and set the shortlink URL metatag in the Advanced section to the path: [site:url]/node/[node:nid]
That got the short(ish) node number URL on the page for me with the right dynamic tokens.
With the AddToAny module loaded, I added the following additional javascript in the "AddToAny" configuration settings "additional options" area:
This should assign the basic Drupal node number url as the path. If you want to redirect that back to a nicer pathauto clean url alias that exists for the node, then ready my blog post about auto-redirecting node number urls back to aliased paths (so people don't bookmark the ugly node number url).
Comment #8
micropat CreditAttribution: micropat commented