You are here

public function LinkGeneratorBase::get_entity_paths in Simple XML sitemap 8

Parameters

string $entity_type: E.g. 'node_type', 'taxonomy_vocabulary'.

array $bundles: E.g. 'page'.

Return value

array $paths

Overrides LinkGeneratorInterface::get_entity_paths

File

src/LinkGeneratorBase.php, line 34
Contains \Drupal\simplesitemap\LinkGeneratorBase.

Class

LinkGeneratorBase

Namespace

Drupal\simplesitemap

Code

public function get_entity_paths($entity_type, $bundles) {
  $this->current_entity_type = $entity_type;
  $i = 0;
  foreach ($bundles as $bundle => $bundle_settings) {
    if (!$bundle_settings['index']) {
      continue;
    }
    $paths = $this
      ->get_paths($bundle);
    if (!is_array($paths)) {

      // Some error catching.
      $this
        ->register_error(self::PLUGIN_ERROR_MESSAGE, array(
        '@plugin' => $this->current_entity_type,
      ));
      return $this->entity_paths;
    }
    foreach ($paths as $id => $path) {
      if (isset($path['path_data']) && (isset($path['path_data']['path']) || !$path['path_data'])) {
        if ($path['path_data'] !== FALSE) {

          // If URLs have not been created yet by the plugin, use the 'path' to create the URLs now.
          if (empty($path['path_data']['urls'])) {
            $path['path_data'] = $this
              ->get_multilang_urls_from_user_input($path['path_data']['path']);
          }
        }

        // If the plugin provided path does not exist, skip this path.
        if (!$path['path_data']) {
          continue;
        }
      }
      else {
        $this
          ->register_error(self::PLUGIN_ERROR_MESSAGE, array(
          '@plugin' => $this->current_entity_type,
        ));
        return $this->entity_paths;
      }

      // Adding path, its options and the resulting URLs returned by the plugin.
      $this->entity_paths[$i]['path_data'] = $path['path_data'];

      // Adding priority if returned by the plugin.
      $this->entity_paths[$i]['priority'] = !empty($path['priority']) ? $path['priority'] : $bundle_settings['priority'];

      // Adding lastmod if returned by the plugin.
      $this->entity_paths[$i]['lastmod'] = isset($path['lastmod']) && is_numeric($path['lastmod']) ? date_iso8601($path['lastmod']) : NULL;
      $i++;
    }
  }
  return $this->entity_paths;
}