/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $tagIds = []; $tags = $property->getValue() === null ? [] : $property->getValue(); foreach ($tags as $tag) { $tagIds[] = $this->tagManager->findOrCreateByName($tag, $userId)->getId(); } $node->setProperty($property->getName(), $tagIds); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null && $value !== false && $value !== 'false' && $value !== '') { $node->setProperty($property->getName(), true); } else { $node->setProperty($property->getName(), false); } }
public function testGetContentDataWrongType() { $type = new ContactSelectionContentType($this->template, $this->contactManager->reveal(), $this->accountManager->reveal(), $this->serializer->reveal(), new CustomerIdConverter(), new IndexComparator()); $this->property->getValue()->willReturn('blabla'); $this->contactManager->getById(Argument::any(), Argument::any())->shouldNotBeCalled(); $this->accountManager->getById(Argument::any(), Argument::any())->shouldNotBeCalled(); $result = $type->getContentData($this->property->reveal()); $this->assertCount(0, $result); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value !== null) { $node->setProperty($property->getName(), $this->removeValidation($this->removeIllegalCharacters($value))); } else { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); } }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); if ($value != null) { $value = \DateTime::createFromFormat('Y-m-d', $value); $node->setProperty($property->getName(), $value); } else { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); } }
public function testWriteMultipleDifferentTypes() { $this->prepareMultipleBlockProperty(); $this->node = $this->getMock('\\Jackalope\\Node', ['setProperty'], [], '', false); $result = []; $this->node->expects($this->any())->method('setProperty')->will($this->returnCallback(function () use(&$result) { $args = func_get_args(); $result[$args[0]] = $args[1]; })); $data = [['type' => 'type1', 'title' => 'Test-Title-1', 'article' => ['Test-Article-1-1', 'Test-Article-1-2'], 'sub-block' => [['type' => 'subType1', 'title' => 'Test-Title-Sub-1', 'article' => 'Test-Article-Sub-1']]], ['type' => 'type2', 'name' => 'Test-Name-2']]; $this->blockProperty->setValue($data); $this->blockContentType->write($this->node, new TranslatedProperty($this->blockProperty, 'de', 'i18n'), 1, 'default', 'de', ''); // check repository node $this->assertEquals(['i18n:de-block1-length' => 2, 'i18n:de-block1-type#0' => $data[0]['type'], 'i18n:de-block1-title#0' => $data[0]['title'], 'i18n:de-block1-article#0' => $data[0]['article'], 'i18n:de-block1-sub-block#0-length' => 1, 'i18n:de-block1-sub-block#0-type#0' => $data[0]['sub-block'][0]['type'], 'i18n:de-block1-sub-block#0-title#0' => $data[0]['sub-block'][0]['title'], 'i18n:de-block1-sub-block#0-article#0' => $data[0]['sub-block'][0]['article'], 'i18n:de-block1-type#1' => $data[1]['type'], 'i18n:de-block1-name#1' => $data[1]['name']], $result); // check resulted structure $this->assertEquals($data, $this->blockProperty->getValue()); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $categoryIds = []; $value = $property->getValue(); if (null === $value) { $node->setProperty($property->getName(), null); return; } foreach ($value as $category) { if (is_numeric($category)) { // int value for id $categoryIds[] = $category; } else { // full category object use only id to save $categoryIds[] = $category['id']; } } $node->setProperty($property->getName(), $categoryIds); }
/** * {@inheritdoc} */ public function remove(NodeInterface $node, PropertyInterface $property, $webspaceKey, $languageCode, $segmentKey = null) { $this->strategy->deleteByPath($property->getValue(), $webspaceKey, $languageCode, $segmentKey); if ($node->hasProperty($property->getName())) { $node->getProperty($property->getName())->remove(); } }
/** * {@inheritDoc} */ public function getViewData(PropertyInterface $property) { return $property->getValue(); }
/** * {@inheritdoc} */ public function getReferencedUuids(PropertyInterface $property) { $uuid = $property->getValue(); return $uuid ? [$uuid] : []; }
/** * {@inheritdoc} */ public function getReferencedUuids(PropertyInterface $property) { $data = $property->getValue(); return $this->getUuids($data); }
/** * {@inheritdoc} */ public function getContentData(PropertyInterface $property) { $value = $property->getValue(); $locale = $property->getStructure()->getLanguageCode(); if ($value === null || !is_array($value) || count($value) === 0) { return []; } $ids = $this->converter->convertIdsToGroupedIds($value, ['a' => [], 'c' => []]); $accounts = $this->accountManager->getByIds($ids['a'], $locale); $contacts = $this->contactManager->getByIds($ids['c'], $locale); $result = array_merge($accounts, $contacts); @usort($result, function ($a, $b) use($value) { $typeA = $a instanceof Contact ? 'c' : 'a'; $typeB = $b instanceof Contact ? 'c' : 'a'; return $this->comparator->compare($typeA . $a->getId(), $typeB . $b->getId(), $value); }); return array_map(function ($entity) { $groups = ['fullContact', 'partialAccount']; if ($entity instanceof Account) { $groups = ['fullAccount', 'partialContact']; } return $this->serializer->serialize($entity, 'array', SerializationContext::create()->setGroups($groups)->setSerializeNull(true)); }, $result); }
/** * gets the value from property. * * @return mixed */ public function getValue() { return $this->property->getValue(); }
/** * @dataProvider provideGetReferencedUuids */ public function testGetReferencedUuids($propertyValue, $expected) { $this->property->getValue()->willReturn($propertyValue); $uuids = $this->type->getReferencedUuids($this->property->reveal()); $this->assertEquals($expected, $uuids); }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey) { $value = $property->getValue(); $node->setProperty($property->getName(), json_encode($value)); }
/** * Returns property-value merged with defaults. * * @param PropertyInterface $property * * @return array */ private function getValue(PropertyInterface $property) { $default = ['presentAs' => null, 'items' => []]; if (!is_array($property->getValue())) { return $default; } return array_merge($default, $property->getValue()); }
/** * {@inheritdoc} */ public function getContentData(PropertyInterface $property) { $data = $property->getValue(); $container = new InternalLinksContainer(isset($data) ? $data : [], $this->contentQueryExecutor, $this->contentQueryBuilder, array_merge($this->getDefaultParams(), $property->getParams()), $this->logger, $property->getStructure()->getWebspaceKey(), $property->getStructure()->getLanguageCode(), $this->showDrafts); return $container->getData(); }
/** * {@inheritDoc} */ public function getContentData(PropertyInterface $property) { $params = array_merge($this->getDefaultParams(), $property->getParams()); $data = $property->getValue(); $container = new SmartContentContainer($this->contentQuery, $this->contentQueryBuilder, $this->tagManager, $params, $property->getStructure()->getWebspaceKey(), $property->getStructure()->getLanguageCode(), null, $this->stopwatch); $container->setConfig($data === null || !is_array($data) ? [] : $data); $pages = $this->loadData($container, $property, $params); $data['page'] = $container->getPage(); $data['hasNextPage'] = $container->getHasNextPage(); $property->setValue($data); return $pages; }
/** * {@inheritdoc} */ public function getReferencedUuids(PropertyInterface $property) { $value = $property->getValue(); if (!array_key_exists('referencedUuids', $value)) { return []; } return $value['referencedUuids']; }
/** * {@inheritdoc} */ public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey = null) { $value = $property->getValue(); if ($value === null || $value === '') { $this->remove($node, $property, $webspaceKey, $languageCode, $segmentKey); return; } $treeValue = $this->getResourceLocator($node, $webspaceKey, $languageCode, $segmentKey); if ($treeValue === '/') { return; } // only if property value is the same as tree value (is different in move / copy / rename workflow) // or the tree value does not exist if ($treeValue === null) { $this->getStrategy()->save($node, $value, $userId, $webspaceKey, $languageCode, $segmentKey); } elseif ($treeValue !== $value) { $this->getStrategy()->move($treeValue, $value, $node, $userId, $webspaceKey, $languageCode, $segmentKey); } $node->setProperty($property->getName(), $value); }