resolveTagNames() public method

Resolves tag names to ids.
public resolveTagNames ( $tagNames ) : array
$tagNames
return array
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getContentData(PropertyInterface $property)
 {
     // check memoize
     $hash = spl_object_hash($property);
     if (array_key_exists($hash, $this->cache)) {
         return $this->cache[$hash];
     }
     /** @var PropertyParameter[] $params */
     $params = array_merge($this->getDefaultParams($property), $property->getParams());
     // prepare filters
     $filters = $property->getValue();
     $filters['excluded'] = [$property->getStructure()->getUuid()];
     // default value of tags/category is an empty array
     if (!array_key_exists('tags', $filters)) {
         $filters['tags'] = [];
     }
     if (!array_key_exists('categories', $filters)) {
         $filters['categories'] = [];
     }
     // extends selected filter with requested tags
     $filters['websiteTags'] = $this->tagRequestHandler->getTags($params['tags_parameter']->getValue());
     $filters['websiteTagsOperator'] = $params['website_tags_operator']->getValue();
     // extends selected filter with requested categories
     $filters['websiteCategories'] = $this->categoryRequestHandler->getCategories($params['categories_parameter']->getValue());
     $filters['websiteCategoriesOperator'] = $params['website_categories_operator']->getValue();
     // resolve tags to id
     if (!empty($filters['tags'])) {
         $filters['tags'] = $this->tagManager->resolveTagNames($filters['tags']);
     }
     // resolve website tags to id
     if (!empty($filters['websiteTags'])) {
         $filters['websiteTags'] = $this->tagManager->resolveTagNames($filters['websiteTags']);
     }
     // get provider
     $provider = $this->getProvider($property);
     $configuration = $provider->getConfiguration();
     // prepare pagination, limitation and options
     $page = 1;
     $limit = array_key_exists('limitResult', $filters) && $configuration->hasLimit() ? $filters['limitResult'] : null;
     $options = ['webspaceKey' => $property->getStructure()->getWebspaceKey(), 'locale' => $property->getStructure()->getLanguageCode()];
     if (isset($params['max_per_page']) && $configuration->hasPagination()) {
         // is paginated
         $page = $this->getCurrentPage($params['page_parameter']->getValue());
         $pageSize = intval($params['max_per_page']->getValue());
         // resolve paginated filters
         $data = $provider->resolveResourceItems($filters, $params, $options, !empty($limit) ? intval($limit) : null, $page, $pageSize);
     } else {
         $data = $provider->resolveResourceItems($filters, $params, $options, !empty($limit) ? intval($limit) : null);
     }
     // append view data
     $filters['page'] = $page;
     $filters['hasNextPage'] = $data->getHasNextPage();
     $filters['referencedUuids'] = $data->getReferencedUuids();
     $filters['paginated'] = $configuration->hasPagination();
     $property->setValue($filters);
     // save result in cache
     return $this->cache[$hash] = $data->getItems();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $value = $property->getValue();
     if ($value instanceof ArrayableInterface) {
         $value = $value->toArray();
     }
     // if whole smart-content container is pushed
     if (isset($value['config'])) {
         $value = $value['config'];
     }
     if (!empty($value['tags'])) {
         $value['tags'] = $this->tagManager->resolveTagNames($value['tags']);
     }
     $node->setProperty($property->getName(), json_encode($value));
 }
 /**
  * Lazy loads the data based on the filter criteria from the config.
  *
  * @param array $excludeUuids
  * @param int   $limit
  * @param int   $offset
  *
  * @return StructureInterface[]
  */
 public function getData($excludeUuids = [], $limit = null, $offset = null)
 {
     if ($this->data === null) {
         // resolve tagNames to ids for loading data
         $config = $this->getConfig();
         if (!empty($config['tags'])) {
             $config['tags'] = $this->tagManager->resolveTagNames($config['tags']);
         }
         // determine limit
         if ($limit === null && isset($config['limitResult'])) {
             $limit = $config['limitResult'];
         }
         $this->data = $this->loadData($config, $excludeUuids, $limit, $offset);
     }
     return $this->data;
 }
Example #4
0
 /**
  * @param $value
  * @param $key
  */
 protected function resolveTags(&$value, $key)
 {
     if (isset($value[$key])) {
         $ids = [];
         $names = [];
         foreach ($value[$key] as $tag) {
             if (is_numeric($tag)) {
                 $ids[] = $tag;
             } else {
                 $names[] = $tag;
             }
         }
         if (!empty($names)) {
             foreach ($this->tagManager->resolveTagNames($names) as $id) {
                 $ids[] = $id;
             }
         }
         $value[$key] = $ids;
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function convert($value)
 {
     return $this->tagManager->resolveTagNames($value);
 }
Example #6
0
 public function testResolveTagNames()
 {
     $tagNames = ['Tag1', 'Tag2', 'Tag3', 'InvalidTag'];
     $tagIds = $this->tagManager->resolveTagNames($tagNames);
     $this->assertEquals([1, 2, 3], $tagIds);
 }