Resolves tag ids to names.
public resolveTagIds ( $tagIds ) : array | ||
$tagIds | ||
Результат | array |
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $data = $node->getPropertyValueWithDefault($property->getName(), '{}'); if (is_string($data)) { $data = json_decode($data, true); } if (!empty($data['tags'])) { $data['tags'] = $this->tagManager->resolveTagIds($data['tags']); } $property->setValue($data); }
/** * {@inheritdoc} */ public function importData(NodeInterface $node, PropertyInterface $property, $value, $userId, $webspaceKey, $languageCode, $segmentKey = null) { $tagNames = []; $tagIds = json_decode($value); if (!empty($tagIds)) { $tagNames = $this->tagManager->resolveTagIds($tagIds); } $property->setValue($tagNames); $this->write($node, $property, $userId, $webspaceKey, $languageCode, $segmentKey); }
public function testResolveTagIds() { $tagIds = [1, 2, 3, 99]; $tagNames = $this->tagManager->resolveTagIds($tagIds); $this->assertEquals(['Tag1', 'Tag2', 'Tag3'], $tagNames); }
/** * {@inheritdoc} */ public function read(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey) { $tags = $this->tagManager->resolveTagIds($node->getPropertyValueWithDefault($property->getName(), [])); $this->setData($tags, $property); }