You are here

public function D8CacheAttachmentsCollector::getMultiple in Drupal 8 Cache Backport 7

Overrides D8Cache::getMultiple

File

./d8cache-ac.cache.inc, line 92

Class

D8CacheAttachmentsCollector
Special cache backend that tracks attachments.

Code

public function getMultiple(&$cids, $allow_invalid = FALSE) {

  // The parent will properly populate $cids, so we can rely on it.
  $cache = parent::getMultiple($cids, $allow_invalid);
  if (!$this->isValid) {
    return $cache;
  }

  // Unpack the cached data and process attachments.
  foreach ($cache as $cid => $item) {
    if (is_array($item->data) && isset($item->data['#d8cache_data'])) {
      drupal_process_attached($item->data);
      $cache[$cid]->data = $item->data['#d8cache_data'];
    }
  }

  // In case there are no cids left, return.
  if (empty($cids)) {
    return $cache;
  }

  // We have multiple cids, so we need to reset after each cache set.
  $attachments_collector = new D8CacheDrupalAttachmentsCollector();
  $attachments_collector->count = count($cids);
  $attachments_collector->previousCollector = $this->currentAttachmentsCollector;
  $this->currentAttachmentsCollector = $attachments_collector;
  foreach ($cids as $cid) {
    $this->attachmentsCollectors[$cid] = $attachments_collector;
  }
  return $cache;
}