Commit 9e4b9574 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2651952 by borisson_: Remove usage of LinkGeneratorInterface::generate from LinksWidget

parent 16b33164
......@@ -8,6 +8,7 @@
namespace Drupal\facets\Plugin\facets\widget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\facets\FacetInterface;
use Drupal\facets\Widget\WidgetInterface;
......@@ -25,14 +26,6 @@ class LinksWidget implements WidgetInterface {
use StringTranslationTrait;
/**
* The link generator.
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface $linkGenerator
* The link generator.
*/
protected $linkGenerator;
/**
* {@inheritdoc}
*/
......@@ -66,7 +59,7 @@ class LinksWidget implements WidgetInterface {
$items[] = $text;
}
else {
$items[] = $this->linkGenerator()->generate($text, $result->getUrl());
$items[] = new Link($text, $result->getUrl());
}
}
}
......@@ -113,17 +106,4 @@ class LinksWidget implements WidgetInterface {
return $query_types['string'];
}
/**
* Gets the link generator.
*
* @return \Drupal\Core\Utility\LinkGeneratorInterface
* The link generator.
*/
protected function linkGenerator() {
if (!isset($this->linkGenerator)) {
$this->linkGenerator = \Drupal::linkGenerator();
}
return $this->linkGenerator;
}
}
......@@ -53,17 +53,6 @@ class LinksWidgetTest extends UnitTestCase {
}
$this->originalResults = $original_results;
$link_generator = $this->getMockBuilder('\Drupal\Core\Utility\LinkGenerator')
->disableOriginalConstructor()
->getMock();
$link_generator->expects($this->atLeastOnce())
->method('generate')
->will($this->returnArgument(0));
$container_builder = new ContainerBuilder();
$container_builder->set('link_generator', $link_generator);
\Drupal::setContainer($container_builder);
$this->widget = new LinksWidget();
}
......@@ -82,7 +71,8 @@ class LinksWidgetTest extends UnitTestCase {
$expected_links = ['Llama (10)', 'Badger (20)', 'Duck (15)', 'Alpaca (9)'];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
$this->assertInstanceOf('\Drupal\Core\Link', $output['#items'][$index]);
$this->assertEquals($value, $output['#items'][$index]->getText());
}
}
......@@ -104,7 +94,8 @@ class LinksWidgetTest extends UnitTestCase {
$expected_links = ['Llama (10)', 'Duck (15)', 'Alpaca (9)'];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
$this->assertInstanceOf('\Drupal\Core\Link', $output['#items'][$index]);
$this->assertEquals($value, $output['#items'][$index]->getText());
}
}
......@@ -132,7 +123,8 @@ class LinksWidgetTest extends UnitTestCase {
'(-) Alpaca (9)',
];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
$this->assertInstanceOf('\Drupal\Core\Link', $output['#items'][$index]);
$this->assertEquals($value, $output['#items'][$index]->getText());
}
}
......@@ -154,7 +146,8 @@ class LinksWidgetTest extends UnitTestCase {
$expected_links = ['Llama', '(-) Badger', 'Duck', 'Alpaca'];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
$this->assertInstanceOf('\Drupal\Core\Link', $output['#items'][$index]);
$this->assertEquals($value, $output['#items'][$index]->getText());
}
// Enable the 'show_numbers' setting again to make sure that the switch
......@@ -173,7 +166,8 @@ class LinksWidgetTest extends UnitTestCase {
'Alpaca (9)',
];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
$this->assertInstanceOf('\Drupal\Core\Link', $output['#items'][$index]);
$this->assertEquals($value, $output['#items'][$index]->getText());
}
}
......
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