Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function addMultiple(array $entities)
 {
     $workspace_id = $this->workspaceId ?: $this->workspaceManager->getActiveWorkspace()->id();
     $values = array();
     foreach ($entities as $entity) {
         $key = $this->buildKey($entity);
         $value = $this->buildValue($entity);
         $values[$key] = $value;
         $this->cache[$workspace_id][$key] = $value;
     }
     $this->keyValueStore($workspace_id)->setMultiple($values);
 }
 /**
  * {@inheritdoc}
  */
 protected function loadLinks($menu_name, MenuTreeParameters $parameters)
 {
     $links = parent::loadLinks($menu_name, $parameters);
     $map = [];
     // Collect all menu_link_content IDs from the links.
     foreach ($links as $i => $link) {
         if ($link['provider'] != 'menu_link_content') {
             continue;
         }
         $metadata = unserialize($link['metadata']);
         $map[$metadata['entity_id']] = $i;
     }
     // Load all menu_link_content entities and remove links for the those that
     // don't belong to the active workspace.
     $active_workspace_id = $this->workspaceManager->getActiveWorkspace()->id();
     $entities = $this->entityTypeManager->getStorage('menu_link_content')->loadMultiple(array_keys($map));
     foreach ($map as $entity_id => $link_id) {
         if (!isset($entities[$entity_id]) || $active_workspace_id != $entities[$entity_id]->workspace->target_id) {
             unset($links[$link_id]);
         }
     }
     return $links;
 }
 /**
  * Helper method to decorate a cache ID.
  *
  * @param string $cid
  * @return string
  */
 protected function decorate($cid)
 {
     return "{$cid}:" . $this->workspaceManager->getActiveWorkspace()->id();
 }
 /**
  * @param string $uuid
  * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
  */
 protected function keyValueStore($uuid)
 {
     $workspace_id = $this->workspaceId ?: $this->workspaceManager->getActiveWorkspace()->id();
     return $this->keyValueFactory->get("entity.index.rev.tree.{$workspace_id}.{$uuid}");
 }
 /**
  * {@inheritdoc}
  */
 public function getActiveWorkspaceId()
 {
     return $this->workspaceManager->getActiveWorkspace()->id();
 }
 /**
  * @return \Drupal\key_value\KeyValueStore\KeyValueStoreSortedSetInterface
  */
 protected function sortedSetStore()
 {
     $workspace_id = $this->workspaceId ?: $this->workspaceManager->getActiveWorkspace()->id();
     return $this->sortedSetFactory->get($this->collectionPrefix . $workspace_id);
 }
 /**
  * {@inheritdoc}
  */
 public function getContext()
 {
     return 'ws.' . $this->workspaceManager->getActiveWorkspace()->id();
 }