You are here

public function NameListFormatListBuilder::buildRow in Name Field 8

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/NameListFormatListBuilder.php, line 89

Class

NameListFormatListBuilder
The name list builder.

Namespace

Drupal\name

Code

public function buildRow(EntityInterface $entity) {
  $row = [];
  $row['label'] = $entity
    ->label();
  $row['id'] = $entity
    ->id();
  $settings = $entity
    ->listSettings();
  $and_options = $this->formatter
    ->getLastDelimitorTypes();
  $and_delimiter = isset($and_options[$settings['and']]) ? $and_options[$settings['and']] : $this
    ->t('-- invalid option --');
  $and_behavior_options = $this->formatter
    ->getLastDelimitorBehaviors(FALSE);
  $and_behavior = isset($and_behavior_options[$settings['delimiter_precedes_last']]) ? $and_behavior_options[$settings['delimiter_precedes_last']] : $this
    ->t('-- invalid option --');
  if ($settings['el_al_min']) {
    $behavior = $this
      ->t('Reduce after @max items and show @min items followed by <em>el al</em>.', [
      '@max' => $settings['el_al_min'],
      '@min' => $settings['el_al_first'],
    ]);
  }
  else {
    $behavior = $this
      ->t('Show all names.');
  }
  $summary = [
    $behavior,
    $this
      ->t('Delimiters: "@delimiter" and @last', [
      '@delimiter' => $settings['delimiter'],
      '@last' => $and_delimiter,
    ]),
    $this
      ->t('Last delimiter: @delimiter', [
      '@delimiter' => $and_behavior,
    ]),
  ];
  if ($entity
    ->isLocked()) {
    $summary[] = t('Default format (locked)');
  }
  $row['settings'] = new FormattableMarkup(implode('<br>', $summary), []);

  // Add a few examples.
  $row['examples'] = $this
    ->examples($entity);
  $operations = $this
    ->buildOperations($entity);
  $row['operations']['data'] = $operations;
  return $row;
}