Skip to content
Snippets Groups Projects
Commit 675b75fb authored by Mark Casias's avatar Mark Casias
Browse files

Issue by ckaotik: Trimmed summary markup.

parent deb4ef66
No related branches found
Tags 7.x-1.0-beta3
No related merge requests found
Smart Trim 8.x-1.2
------------------
Issue by ckaotik: Trimmed summary markup.
Issue #2995557 by jkaeser, slefevre@ccad.edu: Extra space characters after HTML stripping
Issue #3042672 by Phil Wolstenholme: Drupal 9 Deprecated Code Report
Issue #2169583 by danbohea, MegaChriz, thewilkybarkid: Trim certain punctuation from the end of truncated text output before appending suffix
......
......@@ -198,10 +198,7 @@ class SmartTrimFormatter extends FormatterBase {
foreach ($items as $delta => $item) {
if ($settings_summary_handler != 'ignore' && !empty($item->summary)) {
$output = $item->summary_processed;
}
elseif ($item->processed != NULL) {
$output = $item->processed;
$output = $item->summary;
}
else {
$output = $item->value;
......@@ -251,28 +248,30 @@ class SmartTrimFormatter extends FormatterBase {
$output = $truncate->truncateChars($output, $length, $ellipse);
}
}
$element[$delta] = [
'#type' => 'processed_text',
'#text' => $output,
'#format' => $item->format,
];
// Wrap content in container div.
if ($this->getSetting('wrap_output')) {
$output = '<div class="' . $this->getSetting('wrap_class') . '">' . $output . '</div>';
$element[$delta]['#prefix'] = '<div class="' . $this->getSetting('wrap_class') . '">';
$element[$delta]['#suffix'] = '</div>';
}
// Add the link, if there is one!
$link = '';
// The entity must have an id already. Content entities usually get their
// IDs by saving them. In some cases, eg: Inline Entity Form preview there
// is no ID until everything is saved.
// https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Entity.php/function/Entity%3A%3AtoUrl/8.2.x
if ($entity->id()) {
$uri = $entity->hasLinkTemplate('canonical') ? $entity->toUrl() : NULL;
if ($this->getSetting('more_link') && $entity->id() && $entity->hasLinkTemplate('canonical')) {
// But wait! Don't add a more link if the field ends in <!--break-->.
if ($uri && $this->getSetting('more_link') && strpos(strrev($output), strrev('<!--break-->')) !== 0) {
if (strpos(strrev($output), strrev('<!--break-->')) !== 0) {
$more = $this->getSetting('more_text');
$class = $this->getSetting('more_class');
$project_link = Link::fromTextAndUrl($more, $uri);
$project_link = $project_link->toRenderable();
$project_link = $entity->toLink($more)->toRenderable();
$project_link['#attributes'] = [
'class' => [
$class,
......@@ -280,11 +279,9 @@ class SmartTrimFormatter extends FormatterBase {
];
$project_link['#prefix'] = '<div class="' . $class . '">';
$project_link['#suffix'] = '</div>';
$link = render($project_link);
$element[$delta]['more_link'] = $project_link;
}
}
$output .= $link;
$element[$delta] = ['#markup' => $output];
}
return $element;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment