You are here

public function XmlSitemapListBuilder::buildRow in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 src/XmlSitemapListBuilder.php \Drupal\xmlsitemap\XmlSitemapListBuilder::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 EntityListBuilder::buildRow

See also

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

File

src/XmlSitemapListBuilder.php, line 86

Class

XmlSitemapListBuilder
Provides a listing of XmlSitemap.

Namespace

Drupal\xmlsitemap

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\xmlsitemap\XmlSitemapInterface $entity */
  $row['label'] = $entity
    ->label();
  if ($this->moduleHandler
    ->moduleExists('language')) {
    if (isset($entity
      ->getContext()['language'])) {
      $language = $this->languageManager
        ->getLanguage($entity
        ->getContext()['language']);

      // In some cases ::getLanguage() can return NULL value.
      if (!is_null($language) && $language instanceof LanguageInterface) {
        $row['language'] = $language
          ->getName();
      }
      else {
        \Drupal::logger('xmlsitemap')
          ->notice('Cannot determine language for sitemap @id', [
          '@id' => $entity
            ->id(),
        ]);

        // Set as default row value.
        $row['language'] = $this
          ->t('Undefined');
      }
    }
    else {
      $row['language'] = $this
        ->t('Undefined');
    }
  }
  $row['id'] = $entity
    ->id();

  // You probably want a few more properties here...
  return $row + parent::buildRow($entity);
}