/** * Get the array of type links. * * @return array * An array of typed data ids (entity_type and bundle) keyed by * corresponding type URI. */ protected function getTypes() { $cid = 'rest:links:types'; $cache = $this->cache->get($cid); if (!$cache) { $this->writeCache(); $cache = $this->cache->get($cid); } return $cache->data; }
/** * Get the array of relation links. * * Any field can be handled as a relation simply by changing how it is * normalized. Therefore, there is no prior knowledge that can be used here * to determine which fields to assign relation URIs. Instead, each field, * even primitives, are given a relation URI. It is up to the caller to * determine which URIs to use. * * @return array * An array of typed data ids (entity_type, bundle, and field name) keyed * by corresponding relation URI. */ public function getRelations() { $cid = 'rest:links:relations'; $cache = $this->cache->get($cid); if (!$cache) { $this->writeCache(); $cache = $this->cache->get($cid); } return $cache->data; }
/** * {@inheritdoc} */ public function getAliasByPath($path, $langcode = NULL) { if ($path[0] !== '/') { throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path)); } // If no language is explicitly specified we default to the current URL // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. $langcode = $langcode ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(); // Check the path whitelist, if the top-level part before the first / // is not in the list, then there is no need to do anything further, // it is not in the database. if ($path === '/' || !$this->whitelist->get(strtok(trim($path, '/'), '/'))) { return $path; } // During the first call to this method per language, load the expected // paths for the page from cache. if (empty($this->langcodePreloaded[$langcode])) { $this->langcodePreloaded[$langcode] = TRUE; $this->lookupMap[$langcode] = array(); // Load the cached paths that should be used for preloading. This only // happens if a cache key has been set. if ($this->preloadedPathLookups === FALSE) { $this->preloadedPathLookups = array(); if ($this->cacheKey) { if ($cached = $this->cache->get($this->cacheKey)) { $this->preloadedPathLookups = $cached->data; } else { $this->cacheNeedsWriting = TRUE; } } } // Load paths from cache. if (!empty($this->preloadedPathLookups[$langcode])) { $this->lookupMap[$langcode] = $this->storage->preloadPathAlias($this->preloadedPathLookups[$langcode], $langcode); // Keep a record of paths with no alias to avoid querying twice. $this->noAlias[$langcode] = array_flip(array_diff_key($this->preloadedPathLookups[$langcode], array_keys($this->lookupMap[$langcode]))); } } // If we already know that there are no aliases for this path simply return. if (!empty($this->noAlias[$langcode][$path])) { return $path; } // If the alias has already been loaded, return it from static cache. if (isset($this->lookupMap[$langcode][$path])) { return $this->lookupMap[$langcode][$path]; } // Try to load alias from storage. if ($alias = $this->storage->lookupPathAlias($path, $langcode)) { $this->lookupMap[$langcode][$path] = $alias; return $alias; } // We can't record anything into $this->lookupMap because we didn't find any // aliases for this path. Thus cache to $this->noAlias. $this->noAlias[$langcode][$path] = TRUE; return $path; }
/** * Get the array of relation links. * * Any field can be handled as a relation simply by changing how it is * normalized. Therefore, there is no prior knowledge that can be used here * to determine which fields to assign relation URIs. Instead, each field, * even primitives, are given a relation URI. It is up to the caller to * determine which URIs to use. * * @param array $context * Context from the normalizer/serializer operation. * * @return array * An array of typed data ids (entity_type, bundle, and field name) keyed * by corresponding relation URI. */ protected function getRelations($context = array()) { $cid = 'rest:links:relations'; $cache = $this->cache->get($cid); if (!$cache) { $this->writeCache($context); $cache = $this->cache->get($cid); } return $cache->data; }
/** * Get the array of type links. * * @param array $context * Context from the normalizer/serializer operation. * * @return array * An array of typed data ids (entity_type and bundle) keyed by * corresponding type URI. */ protected function getTypes($context = array()) { $cid = 'rest:links:types'; $cache = $this->cache->get($cid); if (!$cache) { $data = $this->writeCache($context); } else { $data = $cache->data; } return $data; }