You are here

protected function NameFormatListBuilder::examples in Name Field 8

Provides some example based on names with various components set.

Parameters

\Drupal\name\Entity\NameFormat $entity: The name format entity.

Return value

\Drupal\Component\Render\FormattableMarkup The example names with formatting applied.

1 call to NameFormatListBuilder::examples()
NameFormatListBuilder::buildRow in src/NameFormatListBuilder.php
Builds a row for an entity in the entity listing.

File

src/NameFormatListBuilder.php, line 105

Class

NameFormatListBuilder
Name format list builder for the admin page.

Namespace

Drupal\name

Code

protected function examples(NameFormat $entity) {
  $this->names = $this->generator
    ->loadSampleValues(4);
  $examples = [];
  foreach ($this->names as $index => $example_name) {
    $formatted = $this->parser
      ->parse($example_name, $entity
      ->get('pattern'));
    if (!strlen($formatted)) {
      $formatted = $this
        ->t('<<@empty>>', [
        '@empty' => $this
          ->t('empty'),
      ]);
    }
    $examples[] = $this
      ->t('(@num) %name', [
      '@num' => $index + 1,
      '%name' => $formatted,
    ]);
  }
  return new FormattableMarkup(implode('<br>', $examples), []);
}