From d6a7afc0dbdba88546c1d28a6c77d3e9867c9f9e Mon Sep 17 00:00:00 2001
From: beram <beram@smile.fr>
Date: Tue, 20 Jun 2017 00:44:11 +0200
Subject: Issue #2732065: Flag links redirect to the system path rather than
 the actual path the user was on.

---
 src/ActionLink/ActionLinkTypeBase.php | 11 +++--------
 src/Tests/LinkTypeFieldEntryTest.php  |  2 +-
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/ActionLink/ActionLinkTypeBase.php b/src/ActionLink/ActionLinkTypeBase.php
index 2cd9ef2..905d93f 100644
--- a/src/ActionLink/ActionLinkTypeBase.php
+++ b/src/ActionLink/ActionLinkTypeBase.php
@@ -5,6 +5,7 @@ namespace Drupal\flag\ActionLink;
 use Drupal\Component\Plugin\PluginBase;
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Link;
+use Drupal\Core\Routing\RedirectDestinationTrait;
 use Drupal\Core\Url;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Cache\CacheableMetadata;
@@ -32,6 +33,7 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
   protected $currentUser;

   use StringTranslationTrait;
+  use RedirectDestinationTrait;

   /**
    * Build a new link type instance and sets the configuration.
@@ -152,14 +154,7 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl
    *  A string containing a destination URL parameter.
    */
   protected function getDestination() {
-    $current_url = Url::fromRoute('<current>');
-    $route_params = $current_url->getRouteParameters();
-
-    if (isset($route_params['destination'])) {
-      return $route_params['destination'];
-    }
-
-    return $current_url->getInternalPath();
+    return $this->getRedirectDestination()->get();
   }

   /**
diff --git a/src/Tests/LinkTypeFieldEntryTest.php b/src/Tests/LinkTypeFieldEntryTest.php
index 7f3d785..efbc58d 100644
--- a/src/Tests/LinkTypeFieldEntryTest.php
+++ b/src/Tests/LinkTypeFieldEntryTest.php
@@ -153,7 +153,7 @@ class LinkTypeFieldEntryTest extends FlagTestBase {
     $this->clickLink($this->flag->getShortText('unflag'));
     $this->assertUrl('flag/details/edit/' . $flag_id . '/' . $this->nodeId, [
       'query' => [
-        'destination' => 'node/' . $this->nodeId,
+        'destination' => '/node/' . $this->nodeId,
       ],
     ]);

--
1.9.1

