You are here

public function EntityUrlGenerator::getDataSets in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityUrlGenerator::getDataSets()
  2. 8.2 src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityUrlGenerator::getDataSets()

@inheritdoc

Overrides UrlGeneratorBase::getDataSets

File

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

Class

EntityUrlGenerator
Class EntityUrlGenerator

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Code

public function getDataSets() : array {
  $data_sets = [];
  $sitemap_entity_types = $this->entityHelper
    ->getSupportedEntityTypes();
  foreach ($this->entitiesManager
    ->setVariants($this->sitemapVariant
    ->id())
    ->getBundleSettings() as $entity_type_name => $bundles) {
    if (!isset($sitemap_entity_types[$entity_type_name])) {
      continue;
    }
    if ($this
      ->isOverwrittenForEntityType($entity_type_name)) {
      continue;
    }
    $entityTypeStorage = $this->entityTypeManager
      ->getStorage($entity_type_name);
    $keys = $sitemap_entity_types[$entity_type_name]
      ->getKeys();
    foreach ($bundles as $bundle_name => $bundle_settings) {
      if ($bundle_settings['index']) {
        $query = $entityTypeStorage
          ->getQuery();
        if (empty($keys['id'])) {
          $query
            ->sort($keys['id']);
        }
        if (!empty($keys['bundle'])) {
          $query
            ->condition($keys['bundle'], $bundle_name);
        }
        if (!empty($keys['status'])) {
          $query
            ->condition($keys['status'], 1);
        }

        // Shift access check to EntityUrlGeneratorBase for language
        // specific access.
        // See https://www.drupal.org/project/simple_sitemap/issues/3102450.
        $query
          ->accessCheck(FALSE);
        $data_set = [
          'entity_type' => $entity_type_name,
          'id' => [],
        ];
        foreach ($query
          ->execute() as $entity_id) {
          $data_set['id'][] = $entity_id;
          if (count($data_set['id']) >= $this->entitiesPerDataset) {
            $data_sets[] = $data_set;
            $data_set['id'] = [];
          }
        }

        // Add the last data set if there are some IDs gathered.
        if (!empty($data_set['id'])) {
          $data_sets[] = $data_set;
        }
      }
    }
  }
  return $data_sets;
}