I want to create a block of service links, but rather than drawing from the current page URL or a specific node, I want my own custom URL.

Here's the code I used:

//- Override $_GET['q'] which is what the service links URL is based on. -//
$orig_url = $_GET['q'];
$_GET['q'] = 'my/custom/path/here';
$share_links = theme('service_links_node_format', service_links_render(NULL, TRUE), 'Share this badge: ');
$_GET['q'] = $orig_url;

Is this a good way to go about it, or is there a better way?

Comments

TheCrow’s picture

This feature was not planned, anyway seems to work well except for the title which will be loaded by the current page.

If you want fix this behaviour you have to change something in the main module, so i would give some tip:

Subst:

function _service_links_get_tags($node, &$settings) {
  ...
    else {
    $title = drupal_get_title();
  ...

}

with :

function _service_links_get_tags($node, &$settings) {
  ...
    else {
    $title = ($settings['title_override'] == SERVICE_LINKS_TAG_TITLE_OVERRIDE) ? $settings['title_text'] : drupal_get_title();
  ...
}

then you may override the settings and print the code using:

$settings = array(
  'title_override' => SERVICE_LINKS_TAG_TITLE_OVERRIDE,
  'title_text' => 'My Title', 
);

// ... your code
print theme(..., service_links_render(NULL, TRUE, $settings));
// ... your code

Not tried but should work :)

joachim’s picture

Title: How to create service links for a custom URL » add ability to create service links for a custom URL
Version: 6.x-2.1 » 6.x-2.x-dev
Category: support » feature
Status: Active » Needs review
StatusFileSize
new659 bytes

Here's a patch.

I'm not that keen on the requirement for a constant to pass in, as it means 3 settings rather than two -- it would be better DX to just pass in 'custom title' and for that to mean you want to use it. But I don't know what the possible keys in $options/$settings are to prevent a clash or inconsistency. Is there anywhere they are documented, as 'custom path' would need adding there?

TheCrow’s picture

Assigned: Unassigned » TheCrow
Status: Needs review » Needs work

#2 is not usable, but will provide this feature being useful in debug time.

TheCrow’s picture

Status: Needs work » Needs review
StatusFileSize
new677 bytes
new745 bytes

Patches to test.

TheCrow’s picture

Status: Needs review » Fixed

Committed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.