Commit aced68bf authored by webchick's avatar webchick

Issue #2570895 by alexpott: FieldPluginBase can duplicate a suffix

parent 9bd93907
......@@ -1260,7 +1260,7 @@ public function renderText($alter) {
$value = strip_tags($value, $alter['preserve_tags']);
}
$suffix = '';
$more_link = '';
if (!empty($alter['trim']) && !empty($alter['max_length'])) {
$length = strlen($value);
$value = $this->renderTrimText($alter, $value);
......@@ -1281,9 +1281,7 @@ public function renderText($alter) {
// @todo Views should expect and store a leading /. See
// https://www.drupal.org/node/2423913.
$more_link = \Drupal::l($more_link_text, CoreUrl::fromUserInput('/' . $more_link_path, array('attributes' => array('class' => array('views-more-link')))));
$suffix .= " " . $more_link;
$more_link = ' ' . $this->linkGenerator()->generate($more_link_text, CoreUrl::fromUserInput('/' . $more_link_path, array('attributes' => array('class' => array('views-more-link')))));
}
}
......@@ -1291,10 +1289,8 @@ public function renderText($alter) {
$value = nl2br($value);
}
// Preserve whether or not the string is safe. Since $suffix comes from
// \Drupal::l(), it is safe to append.
if ($value_is_safe) {
$value = ViewsRenderPipelineMarkup::create($value . $suffix);
$value = ViewsRenderPipelineMarkup::create($value);
}
$this->last_render_text = $value;
......@@ -1305,16 +1301,16 @@ public function renderText($alter) {
$value = $this->renderAsLink($alter, $value, $tokens);
}
// Preserve whether or not the string is safe. Since $suffix comes from
// Preserve whether or not the string is safe. Since $more_link comes from
// \Drupal::l(), it is safe to append. Use SafeMarkup::isSafe() here because
// renderAsLink() can return both safe and unsafe values.
if (SafeMarkup::isSafe($value)) {
return ViewsRenderPipelineMarkup::create($value . $suffix);
return ViewsRenderPipelineMarkup::create($value . $more_link);
}
else {
// If the string is not already marked safe, it is still OK to return it
// because it will be sanitized by Twig.
return $value . $suffix;
return $value . $more_link;
}
}
......
......@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest.
*/
namespace Drupal\Tests\views\Unit\Plugin\field;
namespace Drupal\Tests\views\Unit\Plugin\field {
use Drupal\Core\GeneratedUrl;
use Drupal\Core\Language\Language;
......@@ -227,6 +227,38 @@ public function testRenderAsLinkWithoutPath() {
$this->assertEquals($expected_result, $result);
}
/**
* Test rendering as a link without a path.
*
* @covers ::renderText
*/
public function testRenderTrimmedWithMoreLink() {
$alter = [
'trim' => TRUE,
'max_length' => 7,
'more_link' => TRUE,
// Don't invoke translation.
'ellipsis' => FALSE,
'more_link_text' => 'more link',
];
$this->display->expects($this->any())
->method('getHandlers')
->willReturnMap([
['argument', []],
['field', []],
]);
$this->setUpUrlIntegrationServices();
$field = $this->setupTestField(['alter' => $alter]);
$field->field_alias = 'key';
$row = new ResultRow(['key' => 'a long value']);
$expected_result = 'a long <a href="/%3Cfront%3E" class="views-more-link">more link</a>';
$result = $field->advancedRender($row);
$this->assertEquals($expected_result, $result);
}
/**
* Test rendering of a link with a path and options.
*
......@@ -586,3 +618,12 @@ public function setLinkGenerator(LinkGeneratorInterface $link_generator) {
}
}
}
// @todo Remove as part of https://www.drupal.org/node/2529170.
namespace {
if (!function_exists('base_path')) {
function base_path() {
return '/';
}
}
}
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