function SearchPageListBuilder::buildRow

Same name and namespace in other branches
  1. 9 core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::buildRow()
  2. 8.9.x core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::buildRow()
  3. 11.x core/modules/search/src/SearchPageListBuilder.php \Drupal\search\SearchPageListBuilder::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 for an entity row.

Overrides DraggableListBuilderTrait::buildRow

File

core/modules/search/src/SearchPageListBuilder.php, line 140

Class

SearchPageListBuilder
Defines a class to build a listing of search page entities.

Namespace

Drupal\search

Code

public function buildRow(EntityInterface $entity) {
  /** @var \Drupal\search\SearchPageInterface $entity */
  $row['label'] = $entity->label();
  $row['url']['#markup'] = 'search/' . $entity->getPath();
  // If the search page is active, link to it.
  if ($entity->status()) {
    $row['url'] = [
      '#type' => 'link',
      '#title' => $row['url'],
      '#url' => Url::fromRoute('search.view_' . $entity->id()),
    ];
  }
  $definition = $entity->getPlugin()
    ->getPluginDefinition();
  $row['plugin']['#markup'] = $definition['title'];
  if ($entity->isDefaultSearch()) {
    $status = $this->t('Default');
  }
  elseif ($entity->status()) {
    $status = $this->t('Enabled');
  }
  else {
    $status = $this->t('Disabled');
  }
  $row['status']['#markup'] = $status;
  if ($entity->isIndexable()) {
    $status = $entity->getPlugin()
      ->indexStatus();
    $row['progress']['#markup'] = $this->t('%num_indexed of %num_total indexed', [
      '%num_indexed' => $status['total'] - $status['remaining'],
      '%num_total' => $status['total'],
    ]);
  }
  else {
    $row['progress']['#markup'] = $this->t('Does not use index');
  }
  return $row + parent::buildRow($entity);
}

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