You are here

public function SimpleSitemap::toString in Simple XML sitemap 4.x

Overrides SimpleSitemapInterface::toString

1 call to SimpleSitemap::toString()
SimpleSitemap::__toString in src/Entity/SimpleSitemap.php

File

src/Entity/SimpleSitemap.php, line 115

Class

SimpleSitemap
Defines the simple_sitemap entity.

Namespace

Drupal\simple_sitemap\Entity

Code

public function toString(?int $delta = NULL) : string {
  $status = $this->fetchByStatus ?? self::FETCH_BY_STATUS_PUBLISHED;
  $storage = \Drupal::entityTypeManager()
    ->getStorage('simple_sitemap');
  if ($delta) {
    try {
      return $storage
        ->getChunk($this, $status, $delta);
    } catch (SitemapNotExistsException $e) {
    }
  }
  if ($storage
    ->hasIndex($this, $status)) {
    return $storage
      ->getIndex($this, $status);
  }
  try {
    return $storage
      ->getChunk($this, $status);
  } catch (SitemapNotExistsException $e) {
    return '';
  }
}