You are here

public function EntityUrlGenerator::getDataSets in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\EntityUrlGenerator::getDataSets()
  2. 4.x 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 103

Class

EntityUrlGenerator
Class EntityUrlGenerator @package Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Code

public function getDataSets() {
  $data_sets = [];
  $sitemap_entity_types = $this->entityHelper
    ->getSupportedEntityTypes();
  foreach ($this->generator
    ->setVariants($this->sitemapVariant)
    ->getBundleSettings() as $entity_type_name => $bundles) {
    if (isset($sitemap_entity_types[$entity_type_name])) {

      // Skip this entity type if another plugin is written to override its generation.
      foreach ($this->urlGeneratorManager
        ->getDefinitions() as $plugin) {
        if (isset($plugin['settings']['overrides_entity_type']) && $plugin['settings']['overrides_entity_type'] === $entity_type_name) {
          continue 2;
        }
      }
      $entityTypeStorage = $this->entityTypeManager
        ->getStorage($entity_type_name);
      $keys = $sitemap_entity_types[$entity_type_name]
        ->getKeys();
      foreach ($bundles as $bundle_name => $bundle_settings) {
        if (!empty($bundle_settings['index'])) {
          $query = $entityTypeStorage
            ->getQuery();
          if (empty($keys['id'])) {
            $query
              ->sort($keys['id'], 'ASC');
          }
          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;
}