You are here

public function FilterFormatListBuilder::buildRow in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/filter/src/FilterFormatListBuilder.php \Drupal\filter\FilterFormatListBuilder::buildRow()

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 DraggableListBuilder::buildRow

See also

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

File

core/modules/filter/src/FilterFormatListBuilder.php, line 100

Class

FilterFormatListBuilder
Defines a class to build a listing of filter format entities.

Namespace

Drupal\filter

Code

public function buildRow(EntityInterface $entity) {

  // Check whether this is the fallback text format. This format is available
  // to all roles and cannot be disabled via the admin interface.
  $row['label'] = $entity
    ->label();
  $row['roles'] = [];
  if ($entity
    ->isFallbackFormat()) {
    $fallback_choice = $this->configFactory
      ->get('filter.settings')
      ->get('always_show_fallback_choice');
    if ($fallback_choice) {
      $row['roles']['#markup'] = $this
        ->t('All roles may use this format');
    }
    else {
      $row['roles']['#markup'] = $this
        ->t('This format is shown when no other formats are available');
    }

    // Emphasize the fallback role text since it is important to understand
    // how it works which configuring filter formats. Additionally, it is not
    // a list of roles unlike the other values in this column.
    $row['roles']['#prefix'] = '<em>';
    $row['roles']['#suffix'] = '</em>';
  }
  else {
    $row['roles'] = [
      '#theme' => 'item_list',
      '#items' => filter_get_roles_by_format($entity),
      '#empty' => $this
        ->t('No roles may use this format'),
      '#context' => [
        'list_style' => 'comma-list',
      ],
    ];
  }
  return $row + parent::buildRow($entity);
}