function FilterFormatListBuilder::buildRow

Same name and namespace in other branches
  1. 9 core/modules/filter/src/FilterFormatListBuilder.php \Drupal\filter\FilterFormatListBuilder::buildRow()
  2. 10 core/modules/filter/src/FilterFormatListBuilder.php \Drupal\filter\FilterFormatListBuilder::buildRow()
  3. 11.x core/modules/filter/src/FilterFormatListBuilder.php \Drupal\filter\FilterFormatListBuilder::buildRow()

Overrides DraggableListBuilder::buildRow

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);
}

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