text.module

Same filename and directory in other branches
  1. 11.x core/modules/text/text.module
  2. 10 core/modules/text/text.module
  3. 9 core/modules/text/text.module
  4. 8.9.x core/modules/text/text.module
  5. 7.x modules/field/modules/text/text.module

File

core/modules/text/text.module

View source
<?php


/**
 * @file
 */

use Drupal\text\TextSummary;

/**
 * Generates a trimmed, formatted version of a text field value.
 *
 * If the end of the summary is not indicated using the <!--break--> delimiter
 * 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).
 *
 * @param string $text
 *   The content for which a summary will be generated.
 * @param string $format
 *   The format of the content. If the line break filter is present then we
 *   treat newlines embedded in $text as line breaks. If the htmlcorrector
 *   filter is present, it will be run on the generated summary (if different
 *   from the incoming $text).
 * @param int|numeric-string|null $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.
 *
 * @return string
 *   The generated summary.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use
 *   \Drupal::service(TextSummary::class)->generate() instead.
 *
 * @see https://www.drupal.org/node/3568389
 */
function text_summary($text, $format = NULL, $size = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use \\Drupal::service(TextSummary::class)->generate() instead. See https://www.drupal.org/node/3568389', E_USER_DEPRECATED);
  if (!isset($size)) {
    $size = \Drupal::config('text.settings')->get('default_summary_length');
  }
  return \Drupal::service(TextSummary::class)->generate($text, $format, (int) $size);
}

Functions

Title Deprecated Summary
text_summary

in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal::service(TextSummary::class)->generate() instead.

Generates a trimmed, formatted version of a text field value.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.