We use the ShareThis widget as a block. Country code is in the base path. So a typical blog post has the URL: http://www.example.com/in/blog/drupal-works

When we use a ShareThis service, it shares the URL: http://www.example.com/in//in/blog/drupal-works

This happens because the span attribute st_url has the wrong URL. I traced it down to sharethis/src/Plugin/Block/SharethisWidgetBlock.php code that builds the absolute URL:

        $current_path = Url::fromRoute('')->toString();
        $path = ($this->configuration['sharethis_path'] == 'global') ? '' : $current_path;

        global $base_url;
        $path_obj = Url::fromUri($base_url . '/' . $path,
          array(
            'absolute' => TRUE,
          )
        );
        $mpath = $path_obj->toString();

If I replace $base_url to get:

        $path_obj = Url::fromUri('internal:/' . $path,
          array(
            'absolute' => TRUE,
          )
        );

it works fine for our site. However, I am not sure if using internal is the correct code.

Apologies if this issue turns out to be a duplicate. I searched through the issue queue and found a couple of issues that affected SharethisManager.php, but not SharethisWidgetBlock.php.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

abhijit.nadgouda created an issue. See original summary.

abhijit.nadgouda’s picture

Issue summary: View changes
abhijit.nadgouda’s picture

abhijit.nadgouda’s picture

Status: Active » Needs work
pratik_kamble’s picture

Status: Needs work » Needs review
FileSize
635 bytes

Hi @abhijit.nadgouda,

I have tested your patch. It is generating wrong URL to share. If the current path is 'www.example.com/node/15' then it generating 'www.example.com/15'.

Extra slash is getting added to the URL. Added patch to fix the issue.

@purushotamrai please review the patch.

purushotam.rai’s picture

Agree with @pratik_kamble, we don't need an extra slash, rest works fine.

purushotam.rai’s picture

Status: Needs review » Reviewed & tested by the community

  • purushotam.rai committed 6a7a20b on 8.x-2.x
    Issue #2910803 by abhijit.nadgouda, purushotam.rai, pratik_kamble:...
purushotam.rai’s picture

Status: Reviewed & tested by the community » Fixed

Pushed to 8.x-2.x

Thanks to all for your valuable inputs.

Thanks and Regards

Status: Fixed » Closed (fixed)

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

Muath Khraisat’s picture

I still have the problem. The following patch should resolve it.

kostyashupenko’s picture

FileSize
872 bytes
375 bytes

Reroll of #11 against 8.x-2.x