You are here

protected function CustomUrlGenerator::processDataSet in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\CustomUrlGenerator::processDataSet()
  2. 4.x src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php \Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\CustomUrlGenerator::processDataSet()

@inheritdoc

Overrides UrlGeneratorBase::processDataSet

File

src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php, line 112

Class

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

Namespace

Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator

Code

protected function processDataSet($data_set) {

  // todo: Change to different function, as this also checks if current user has access. The user however varies depending if process was started from the web interface or via cron/drush. Use getUrlIfValidWithoutAccessCheck()?
  if (!$this->pathValidator
    ->isValid($data_set['path'])) {

    //        if (!(bool) $this->pathValidator->getUrlIfValidWithoutAccessCheck($data['path'])) {
    $this->logger
      ->m(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE, [
      '@path' => $data_set['path'],
      '@custom_paths_url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap/custom',
    ])
      ->display('warning', 'administer sitemap settings')
      ->log('warning');
    return FALSE;
  }
  $url_object = Url::fromUserInput($data_set['path'], [
    'absolute' => TRUE,
  ]);
  $path = $url_object
    ->getInternalPath();
  if ($this->batchSettings['remove_duplicates'] && $this
    ->pathProcessed($path)) {
    return FALSE;
  }
  $entity = $this->entityHelper
    ->getEntityFromUrlObject($url_object);
  $path_data = [
    'url' => $url_object,
    'lastmod' => method_exists($entity, 'getChangedTime') ? date_iso8601($entity
      ->getChangedTime()) : NULL,
    'priority' => isset($data_set['priority']) ? $data_set['priority'] : NULL,
    'changefreq' => !empty($data_set['changefreq']) ? $data_set['changefreq'] : NULL,
    'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId') ? $this
      ->getImages($entity
      ->getEntityTypeId(), $entity
      ->id()) : [],
    'meta' => [
      'path' => $path,
    ],
  ];

  // Additional info useful in hooks.
  if (NULL !== $entity) {
    $path_data['meta']['entity_info'] = [
      'entity_type' => $entity
        ->getEntityTypeId(),
      'id' => $entity
        ->id(),
    ];
  }
  return $path_data;
}