diff --git a/config/schema/smart_trim.schema.yml b/config/schema/smart_trim.schema.yml index 0205a74..b05f128 100644 --- a/config/schema/smart_trim.schema.yml +++ b/config/schema/smart_trim.schema.yml @@ -26,6 +26,9 @@ field.formatter.settings.smart_trim: more_text: type: string label: 'More link text' + wrap_more_link: + type: string + label: 'Wrap more link' summary_handler: type: string label: 'Summary handler' diff --git a/src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php b/src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php index f10bfb2..0b60c9c 100644 --- a/src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php +++ b/src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php @@ -28,7 +28,8 @@ use Drupal\smart_trim\Truncate\TruncateHTML; * "more_link" = FALSE, * "more_text" = "Read more", * "summary_handler" = "full", - * "trim_options" = "" + * "trim_options" = "", + * "wrap_more_link" = FALSE * } * ) */ @@ -45,6 +46,7 @@ class SmartTrimFormatter extends FormatterBase { 'wrap_output' => 0, 'wrap_class' => 'trimmed', 'more_link' => 0, + 'wrap_more_link' => 0, 'more_class' => 'more-link', 'more_text' => 'More', 'summary_handler' => 'full', @@ -137,6 +139,13 @@ class SmartTrimFormatter extends FormatterBase { ], ]; + $element['wrap_more_link'] = array( + '#title' => $this->t('Wrap more link?'), + '#type' => 'checkbox', + '#default_value' => $this->getSetting('wrap_more_link'), + '#description' => $this->t('Adds a wrapper div to more link.'), + ); + if ($this->fieldDefinition->getType() == 'text_with_summary') { $element['summary_handler'] = [ '#title' => $this->t('Summary'), @@ -180,7 +189,11 @@ class SmartTrimFormatter extends FormatterBase { } if ($this->getSetting('more_link')) { $trim_string .= ", " . $this->t("with more link"); + if ($this->getSetting('wrap_more_link')) { + $trim_string .= " " . $this->t(" (wrapped)"); + } } + $summary[] = $trim_string; return $summary; @@ -278,8 +291,10 @@ class SmartTrimFormatter extends FormatterBase { $class, ], ]; - $project_link['#prefix'] = '
'; - $project_link['#suffix'] = '
'; + if ($this->getSetting('wrap_more_link')) { + $project_link['#prefix'] = '
'; + $project_link['#suffix'] = '
'; + } $link = render($project_link); } }