function PathAliasListBuilder::buildRow

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

Overrides EntityListBuilder::buildRow

File

core/modules/path/src/PathAliasListBuilder.php, line 161

Class

PathAliasListBuilder
Defines a class to build a listing of path_alias entities.

Namespace

Drupal\path

Code

public function buildRow(EntityInterface $entity) {
    
    /** @var \Drupal\Core\Path\Entity\PathAlias $entity */
    $langcode = $entity->language()
        ->getId();
    $alias = $entity->getAlias();
    $path = $entity->getPath();
    $url = Url::fromUserInput($path);
    $row['data']['alias']['data'] = [
        '#type' => 'link',
        '#title' => $alias,
        '#url' => $url,
    ];
    // Create a new URL for linking to the un-aliased system path.
    $system_url = Url::fromUri("base:{$path}");
    $row['data']['path']['data'] = [
        '#type' => 'link',
        '#title' => $path,
        '#url' => $system_url,
    ];
    if ($this->languageManager
        ->isMultilingual()) {
        $row['data']['language_name'] = $this->languageManager
            ->getLanguageName($langcode);
    }
    $row['data']['operations']['data'] = $this->buildOperations($entity);
    // If the system path maps to a different URL alias, highlight this table
    // row to let the user know of old aliases.
    if ($alias != $this->aliasManager
        ->getAliasByPath($path, $langcode)) {
        $row['class'] = [
            'warning',
        ];
    }
    return $row;
}

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