You are here

protected function EntityUrlGenerator::processEntity in Simple XML sitemap 4.x

1 call to EntityUrlGenerator::processEntity()
EntityUrlGenerator::processDataSet in src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
@inheritdoc

File

src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php, line 208

Class

EntityUrlGenerator
Class EntityUrlGenerator

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Code

protected function processEntity(ContentEntityInterface $entity) : array {
  $entity_settings = $this->entitiesManager
    ->setVariants($this->sitemapVariant
    ->id())
    ->getEntityInstanceSettings($entity
    ->getEntityTypeId(), $entity
    ->id());
  if (empty($entity_settings['index'])) {
    throw new SkipElementException();
  }
  $url_object = $entity
    ->toUrl()
    ->setAbsolute();

  // Do not include external paths.
  if (!$url_object
    ->isRouted()) {
    throw new SkipElementException();
  }
  return [
    'url' => $url_object,
    'lastmod' => method_exists($entity, 'getChangedTime') ? date('c', $entity
      ->getChangedTime()) : NULL,
    'priority' => $entity_settings['priority'] ?? NULL,
    'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
    'images' => !empty($entity_settings['include_images']) ? $this
      ->getEntityImageData($entity) : [],
    // Additional info useful in hooks.
    'meta' => [
      'path' => $url_object
        ->getInternalPath(),
      'entity_info' => [
        'entity_type' => $entity
          ->getEntityTypeId(),
        'id' => $entity
          ->id(),
      ],
    ],
  ];
}