diff --git a/core/modules/text/config/install/text.settings.yml b/core/modules/text/config/install/text.settings.yml index 1ff3cbcc9c..15697acf96 100644 --- a/core/modules/text/config/install/text.settings.yml +++ b/core/modules/text/config/install/text.settings.yml @@ -1 +1,2 @@ default_summary_length: 600 +summary_marker: '' \ No newline at end of file diff --git a/core/modules/text/config/schema/text.schema.yml b/core/modules/text/config/schema/text.schema.yml index dfc92cd2ba..1ea881843f 100644 --- a/core/modules/text/config/schema/text.schema.yml +++ b/core/modules/text/config/schema/text.schema.yml @@ -7,6 +7,9 @@ text.settings: default_summary_length: type: integer label: 'Default summary length' + summary_marker: + type: string + label: 'Summary marker' field.storage_settings.text: type: mapping diff --git a/core/modules/text/text.install b/core/modules/text/text.install new file mode 100644 index 0000000000..a4bed0a226 --- /dev/null +++ b/core/modules/text/text.install @@ -0,0 +1,13 @@ +getEditable('text.settings')->set('summary_marker', '')->save(TRUE); +} diff --git a/core/modules/text/text.module b/core/modules/text/text.module index a8c2b847fe..918a99e875 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -41,7 +41,7 @@ function text_help($route_name, RouteMatchInterface $route_match) { /** * Generates a trimmed, formatted version of a text field value. * - * If the end of the summary is not indicated using the delimiter + * If the end of the summary is not indicated using the summary marker * then we generate the summary automatically, trying to end it at a sensible * place such as the end of a paragraph, a line break, or the end of a sentence * (in that order of preference). @@ -55,7 +55,7 @@ function text_help($route_name, RouteMatchInterface $route_match) { * from the incoming $text). * @param $size * The desired character length of the summary. If omitted, the default value - * will be used. Ignored if the special delimiter is present in $text. + * will be used. Ignored if a summary marker is present in $text. * * @return * The generated summary. @@ -66,17 +66,19 @@ function text_summary($text, $format = NULL, $size = NULL) { $size = \Drupal::config('text.settings')->get('default_summary_length'); } - // Find where the delimiter is in the body - $delimiter = strpos($text, ''); + // Find where the summary marker is in the body. + $summary_marker = \Drupal::config('text.settings')->get('summary_marker'); + $summary_marker_position = strpos($text, $summary_marker); - // If the size is zero, and there is no delimiter, the entire body is the summary. - if ($size == 0 && $delimiter === FALSE) { + // If the size is zero, and there is no summary marker, the entire body is + // the summary. + if ($size == 0 && $summary_marker_position === FALSE) { return $text; } - // If a valid delimiter has been specified, use it to chop off the summary. - if ($delimiter !== FALSE) { - return substr($text, 0, $delimiter); + // If a summary marker has been found, use it to chop off the summary. + if ($summary_marker_position !== FALSE) { + return substr($text, 0, $summary_marker_position); } // Retrieve the filters of the specified text format, if any. @@ -95,7 +97,7 @@ function text_summary($text, $format = NULL, $size = NULL) { return $text; } - // If the delimiter has not been specified, try to split at paragraph or + // If the summary marker has not been specified, try to split at paragraph or // sentence boundaries. // The summary may not be longer than maximum length specified. Initial slice.