Commit bd717bda authored by StryKaizer's avatar StryKaizer Committed by borisson_

Issue #2856067 by StryKaizer, gnuget: Use base path instead of url object for...

Issue #2856067 by StryKaizer, gnuget: Use base path instead of url object for facet source getPath()
parent ec781865
......@@ -3,7 +3,6 @@
namespace Drupal\core_search_facets\Plugin\facets\facet_source;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface;
use Drupal\facets\FacetInterface;
use Drupal\facets\FacetSource\FacetSourcePluginBase;
......@@ -111,9 +110,9 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
public function getPath() {
$search_page = $this->request->attributes->get('entity');
if ($search_page instanceof SearchPageInterface) {
return Url::fromUserInput('/search/' . $search_page->getPath());
return '/search/' . $search_page->getPath();
}
return Url::fromUserInput('/');
return '/';
}
/**
......
......@@ -40,11 +40,9 @@ interface FacetSourcePluginInterface extends PluginFormInterface, DependentPlugi
public function getQueryTypesForFacet(FacetInterface $facet);
/**
* Returns the url of the facet source, used to build the facet url.
* Returns the path of the facet source, used to build the facet url.
*
* @return \Drupal\Core\Url
* The url object for the facet if it's set, a url object to the current
* page otherwise.
* @return string The path.
*/
public function getPath();
......
......@@ -116,14 +116,14 @@ class SearchApiDisplay extends FacetSourcePluginBase implements SearchApiFacetSo
* {@inheritdoc}
*/
public function getPath() {
// The implementation in search api tells us that this is a url object only
// if a path is defined, and null if that isn't done. This means that we
// have to check for this + create our own Url object if that's needed.
if ($this->getDisplay()->getUrl() instanceof Url) {
return $this->getDisplay()->getUrl();
// The implementation in search api tells us that this is a base path only
// if a path is defined, and false if that isn't done. This means that we
// have to check for this + create our own uri if that's needed.
if ($this->getDisplay()->getPath()) {
return $this->getDisplay()->getPath();
}
return Url::createFromRequest($this->request);
return \Drupal::service('path.current')->getPath();
}
/**
......
......@@ -2,6 +2,7 @@
namespace Drupal\facets\Plugin\facets\url_processor;
use Drupal\Core\Url;
use Drupal\facets\FacetInterface;
use Drupal\facets\UrlProcessor\UrlProcessorPluginBase;
use Symfony\Component\HttpFoundation\Request;
......@@ -62,11 +63,17 @@ class QueryString extends UrlProcessorPluginBase {
// Set the url alias from the the facet object.
$this->urlAlias = $facet->getUrlAlias();
$url = $facet->getFacetSource()->getPath();
$url->setOption('attributes', ['rel' => 'nofollow']);
$request = $this->request;
if ($facet->getFacetSource()->getPath()) {
$request = Request::create($facet->getFacetSource()->getPath());
}
/** @var \Drupal\facets\Result\ResultInterface[] $results */
foreach ($results as &$result) {
// Reset the URL for each result.
$url = Url::createFromRequest($request);
$url->setOption('attributes', ['rel' => 'nofollow']);
// Sets the url for children.
if ($children = $result->getChildren()) {
$this->buildUrls($facet, $children);
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\facets\Unit\Plugin\url_processor;
use Drupal\Core\Url;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Entity\FacetSource;
use Drupal\facets\Plugin\facets\url_processor\QueryString;
......@@ -283,7 +282,7 @@ class QueryStringTest extends UnitTestCase {
->disableOriginalConstructor()
->getMock();
$fsi->method('getPath')
->willReturn(new Url('test'));
->willReturn('test');
$manager = $this->getMockBuilder('\Drupal\facets\FacetSource\FacetSourcePluginManager')
->disableOriginalConstructor()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment