- * @param string $from
- * @return $this
- */
- public function setGenerateFrom($from) {
- $this->generateFrom = $from;
- return $this;
- }
-
- /**
- * Adds all operations to the batch and starts it.
- */
- public function startGeneration() {
- $this->batch->setBatchInfo([
- 'from' => $this->generateFrom,
- 'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit'))
- ? $this->generator->getSetting('batch_process_limit') : NULL,
- 'max_links' => $this->generator->getSetting('max_links', 2000),
- 'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE),
- 'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE),
- 'entity_types' => $this->generator->getBundleSettings(),
- 'base_url' => $this->generator->getSetting('base_url', ''),
- ]);
- // Add custom link generating operation.
- $this->batch->addOperation('generateCustomUrls', $this->getCustomUrlsData());
-
- // Add entity link generating operations.
- foreach ($this->getEntityTypeData() as $data) {
- $this->batch->addOperation('generateBundleUrls', $data);
- }
- $this->batch->start();
- }
-
- /**
- * Returns a batch-ready data array for custom link generation.
- *
- * @return array
- * Data to be processed.
- */
- protected function getCustomUrlsData() {
- $paths = [];
- foreach ($this->generator->getCustomLinks() as $i => $custom_path) {
- $paths[$i]['path'] = $custom_path['path'];
- $paths[$i]['priority'] = isset($custom_path['priority']) ? $custom_path['priority'] : NULL;
- // todo: implement lastmod.
- $paths[$i]['lastmod'] = NULL;
- }
- return $paths;
- }
-
- /**
- * Collects entity metadata for entities that are set to be indexed
- * and returns an array of batch-ready data sets for entity link generation.
- *
- * @return array
- */
- protected function getEntityTypeData() {
- $data_sets = [];
- $sitemap_entity_types = $this->entityHelper->getSitemapEntityTypes();
- $entity_types = $this->generator->getBundleSettings();
- foreach ($entity_types as $entity_type_name => $bundles) {
- if (isset($sitemap_entity_types[$entity_type_name])) {
- $keys = $sitemap_entity_types[$entity_type_name]->getKeys();
-
- // Menu fix.
- $keys['bundle'] = $entity_type_name == 'menu_link_content' ? 'menu_name' : $keys['bundle'];
-
- foreach ($bundles as $bundle_name => $bundle_settings) {
- if ($bundle_settings['index']) {
- $data_sets[] = [
- 'bundle_settings' => $bundle_settings,
- 'bundle_name' => $bundle_name,
- 'entity_type_name' => $entity_type_name,
- 'keys' => $keys,
- ];
- }
- }
- }
- }
- return $data_sets;
- }
-
- /**
- * Wrapper method which takes links along with their options, lets other
- * modules alter the links and then generates and saves the sitemap.