You are here

protected function XmlSitemapStorage::doLoadMultiple in XML sitemap 8

Same name and namespace in other branches
  1. 2.x src/XmlSitemapStorage.php \Drupal\xmlsitemap\XmlSitemapStorage::doLoadMultiple()

Performs storage-specific loading of entities.

Override this method to add custom functionality directly after loading. This is always called, while self::postLoad() is only called when there are actual results.

Parameters

array|null $ids: (optional) An array of entity IDs, or NULL to load all entities.

Return value

\Drupal\Core\Entity\EntityInterface[] Associative array of entities, keyed on the entity ID.

Overrides ConfigEntityStorage::doLoadMultiple

File

src/XmlSitemapStorage.php, line 78

Class

XmlSitemapStorage
XmlSitemap storage service class.

Namespace

Drupal\xmlsitemap

Code

protected function doLoadMultiple(array $ids = NULL) {
  $entities = parent::doLoadMultiple($ids);

  // Load the auxiliar xmlsitemap data and attach it to the entity.
  foreach ($entities as $entity) {
    $settings = $this->state
      ->get('xmlsitemap.' . $entity
      ->id(), [
      'chunks' => NULL,
      'links' => NULL,
      'max_filesize' => NULL,
      'updated' => NULL,
    ]);
    foreach ($settings as $setting => $value) {
      $entity->{$setting} = $value;
    }

    // Load the entity URI.
    $entity->uri = xmlsitemap_sitemap_uri($entity);

    // Load in the default contexts if they haven't been set yet.
    $contexts = xmlsitemap_get_context_info();
    foreach ($contexts as $context_key => $context) {
      if (!isset($entity->context[$context_key]) && isset($context['default'])) {
        $entity->context[$context_key] = $context['default'];
      }
    }

    // Remove invalid contexts.
    $entity->context = array_intersect_key($entity->context, $contexts);
  }
  return $entities;
}