Inheritance: extends ItemMetadata
Ejemplo n.º 1
0
 public function fromProperty(PropertyMetadata $property, $locale = null)
 {
     if (true === $property->isLocalized()) {
         return $this->localizedContentName($property->getName(), $locale);
     }
     return $this->contentname($property->getName());
 }
Ejemplo n.º 2
0
 /**
  * It should create a translated property.
  *
  * @depends testCreateProperty
  */
 public function testCreateTranslated()
 {
     $this->setUpProperty($this->property1);
     $this->namespaceRegistry->getPrefix('content_localized')->willReturn('i18n');
     $translatedProperty = $this->factory->createTranslatedProperty($this->property1->reveal(), 'de');
     $this->assertEquals('de', $translatedProperty->getLocalization());
     $this->assertEquals('i18n:de-name', $translatedProperty->getName());
 }
Ejemplo n.º 3
0
 private function doGetProperty($name, $contentTypeName, $locale)
 {
     $this->propertyMetadata->getType()->willReturn($contentTypeName);
     $this->structureMetadata->getProperty($name)->willReturn($this->propertyMetadata);
     $this->contentTypeManager->get($contentTypeName)->willReturn($this->contentType->reveal());
     if ($locale) {
         $this->propertyFactory->createTranslatedProperty($this->propertyMetadata->reveal(), $locale, Argument::type(StructureBridge::class))->willReturn($this->legacyProperty->reveal());
     } else {
         $this->propertyFactory->createProperty($this->propertyMetadata->reveal(), $locale)->willReturn($this->legacyProperty->reveal());
     }
     $this->contentType->read($this->node->reveal(), $this->legacyProperty->reveal(), null, null, null)->shouldBeCalledTimes(1);
     $property = $this->structure->getProperty($name);
     $this->assertInstanceOf(PropertyValue::class, $property);
     $this->assertEquals($name, $property->getName());
 }
Ejemplo n.º 4
0
 /**
  * It should throw an exception if the property is required but the value is null.
  *
  * @expectedException Sulu\Component\Content\Exception\MandatoryPropertyException
  */
 public function testThrowExceptionPropertyRequired()
 {
     $document = new TestContentDocument($this->structure->reveal());
     $document->setStructureType('foobar');
     $this->persistEvent->getDocument()->willReturn($document);
     // map the structure type
     $this->persistEvent->getLocale()->willReturn('fr');
     // map the content
     $this->inspector->getStructureMetadata($document)->willReturn($this->structureMetadata->reveal());
     $this->inspector->getWebspace($document)->willReturn('webspace');
     $this->structureMetadata->getProperties()->willReturn(['prop1' => $this->structureProperty->reveal()]);
     $this->structureProperty->isRequired()->willReturn(true);
     $this->structure->getProperty('prop1')->willReturn($this->propertyValue->reveal());
     $this->propertyValue->getValue()->willReturn(null);
     $this->structureMetadata->getName()->willReturn('test');
     $this->structureMetadata->getResource()->willReturn('/path/to/resource.xml');
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
Ejemplo n.º 5
0
 /**
  * Sets the ResourceSegment to the given property of the given document.
  *
  * @param ResourceSegmentBehavior $document
  * @param PropertyMetadata $property
  */
 private function persistDocument(ResourceSegmentBehavior $document, PropertyMetadata $property)
 {
     $document->getStructure()->getProperty($property->getName())->setValue($document->getResourceSegment());
 }
Ejemplo n.º 6
0
 private function getContentField(PropertyMetadata $property)
 {
     $field = $this->factory->createMetadataExpression(sprintf('object.getStructure().%s.getValue()', $property->getName()));
     return $field;
 }
Ejemplo n.º 7
0
 /**
  * Upgrades the given property to the new date representation.
  *
  * @param PropertyMetadata $property
  * @param NodeInterface $node
  * @param bool $up
  */
 private function upgradeProperty(PropertyMetadata $property, NodeInterface $node, $locale, $up)
 {
     $name = sprintf('i18n:%s-%s', $locale, $property->getName());
     if (!$node->hasProperty($name)) {
         return;
     }
     $value = $node->getPropertyValue($name);
     if ($up) {
         $value = $this->upgradeDate($value);
     } else {
         $value = $this->downgradeDate($value);
     }
     $node->setProperty($name, $value);
 }
Ejemplo n.º 8
0
 /**
  * Creates and returns a property-array.
  *
  * @param PropertyMetadata $property
  * @param PropertyValue $propertyValue
  * @param string $format
  *
  * @return array
  */
 protected function getPropertyData(PropertyMetadata $property, $propertyValue, $format)
 {
     return $this->createProperty($property->getName(), $this->contentExportManager->export($property->getType(), $propertyValue), $this->contentExportManager->getOptions($property->getType(), $format), $property->getType());
 }