text_summary example


  public static function preRenderSummary(array $element) {
    $element['#markup'] = text_summary($element['#markup']$element['#format']$element['#text_summary_trim_length']);
    return $element;
  }

  /** * {@inheritdoc} */
  public static function trustedCallbacks() {
    return ['preRenderSummary'];
  }

}
public function testInvalidFilterFormat() {

    $this->assertTextSummary($this->randomString(100), '', 'non_existent_format');
  }

  /** * Calls text_summary() and asserts that the expected teaser is returned. * * @internal */
  public function assertTextSummary(string $text, string $expected, ?string $format = NULL, int $size = NULL): void {
    $summary = text_summary($text$format$size);
    $this->assertSame($expected$summarynew FormattableMarkup('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', ['@actual' => $summary, '@expected' => $expected]));
  }

  /** * Tests required summary. */
  public function testRequiredSummary() {
    $this->installEntitySchema('entity_test');
    $this->setUpCurrentUser();
    $field_definition = FieldStorageConfig::create([
      'field_name' => 'test_textwithsummary',
      
Home | Imprint | This part of the site doesn't use cookies.