Ejemplo n.º 1
0
 /**
  * @param FieldMetadata $fieldMetadata
  * @return array
  */
 protected function initMergeModes(FieldMetadata $fieldMetadata)
 {
     $fieldMetadata->addMergeMode(MergeModes::REPLACE);
     if ($fieldMetadata->isCollection()) {
         $fieldMetadata->addMergeMode(MergeModes::UNITE);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param EntityData $entityData
  * @param FieldMetadata $metadata
  */
 public function __construct(EntityData $entityData, FieldMetadata $metadata)
 {
     $this->entityData = $entityData;
     $this->metadata = $metadata;
     if ($metadata->getMergeMode()) {
         $this->mode = $metadata->getMergeMode();
     }
 }
Ejemplo n.º 3
0
 /**
  * Prepare metadata field.
  *
  * @param FieldMetadata $fieldMetadata
  */
 public function prepareFieldMetadataPropertyPath(FieldMetadata $fieldMetadata)
 {
     $className = $fieldMetadata->getSourceClassName();
     $fieldName = $fieldMetadata->getSourceFieldName();
     if ($this->isExtendField($className, $fieldName)) {
         $fieldMetadata->set('property_path', $fieldName);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param $entity
  * @param FieldMetadata $metadata
  * @param int $count
  * @param $expectedValue
  *
  * @dataProvider getValueDataProvider
  */
 public function testGetValue($entity, FieldMetadata $metadata, $count, $expectedValue)
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $repository = $this->getMockBuilder('Oro\\Bundle\\ActivityListBundle\\Entity\\Repository\\ActivityListRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('getRecordsCountForTargetClassAndId')->with(ClassUtils::getClass($entity), $entity->getId(), [$metadata->get('type')])->willReturn($count);
     $em->expects($this->once())->method('getRepository')->willReturn($repository);
     $this->registry->expects($this->once())->method('getManagerForClass')->willReturn($em);
     $this->assertEquals($expectedValue, $this->accessor->getValue($entity, $metadata));
 }
Ejemplo n.º 5
0
 /**
  * Prepare metadata field.
  *
  * @param FieldMetadata $fieldMetadata
  */
 public function prepareFieldMetadataPropertyPath(FieldMetadata $fieldMetadata)
 {
     $className = $fieldMetadata->getSourceClassName();
     $fieldName = $fieldMetadata->getSourceFieldName();
     $extendConfig = $this->getFieldExtendConfig($className, $fieldName);
     if ($extendConfig && $extendConfig->is('is_extend')) {
         $fieldMetadata->set('property_path', $fieldName);
         $fieldMetadata->set('display', true);
     }
 }
Ejemplo n.º 6
0
 /**
  * Render field value to string
  *
  * @param mixed $value
  * @param FieldMetadata $metadata
  * @param object $entity
  * @return string
  */
 public function renderFieldValue($value, FieldMetadata $metadata, $entity)
 {
     $template = $metadata->get('template') ?: $this->defaultTemplate;
     if (is_array($value) || $value instanceof \Traversable) {
         $isListValue = true;
         $stringValue = $this->convertListToStringArray($value, $metadata);
     } else {
         $isListValue = false;
         $stringValue = $this->convertToString($value, $metadata);
     }
     return $this->environment->render($template, array('convertedValue' => $stringValue, 'isListValue' => $isListValue, 'metadata' => $metadata, 'value' => $value));
 }
 /**
  * @param object $relatedEntity
  * @param FieldMetadata $metadata
  * @param object $value
  */
 protected function setRelatedEntityValue($relatedEntity, FieldMetadata $metadata, $value)
 {
     if ($metadata->has('setter')) {
         $setter = $metadata->get('setter');
         $relatedEntity->{$setter}($value);
     } else {
         try {
             $this->getPropertyAccessor()->setValue($relatedEntity, $metadata->getDoctrineMetadata()->getFieldName(), $value);
         } catch (NoSuchPropertyException $e) {
             // If setter is not exist
             $reflection = new \ReflectionProperty(ClassUtils::getClass($relatedEntity), $metadata->getDoctrineMetadata()->getFieldName());
             $reflection->setAccessible(true);
             $reflection->setValue($relatedEntity, $value);
         }
     }
 }
Ejemplo n.º 8
0
 public function testIsCollectionTrueWhenManyToOneDefinedBySourceEntity()
 {
     $className = 'Foo\\Entity';
     $sourceClassName = 'Bar\\Entity';
     $this->entityMetadata->expects($this->once())->method('getClassName')->will($this->returnValue($className));
     $this->fieldMetadata->setEntityMetadata($this->entityMetadata);
     $this->fieldMetadata->set('source_class_name', $sourceClassName);
     $this->doctrineMetadata->expects($this->once())->method('isAssociation')->will($this->returnValue(true));
     $this->doctrineMetadata->expects($this->once())->method('isManyToMany')->will($this->returnValue(false));
     $this->doctrineMetadata->expects($this->once())->method('isManyToOne')->will($this->returnValue(true));
     $this->assertTrue($this->fieldMetadata->isCollection());
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getValue($entity, FieldMetadata $metadata)
 {
     if ($metadata->has('activity') && $metadata->has('type') && $metadata->get('activity') === true) {
         return $this->getActivity($entity, $metadata->get('type'));
     }
     return parent::getValue($entity, $metadata);
 }
Ejemplo n.º 10
0
 /**
  * @param FieldMetadata $fieldMetadata
  * @return array
  */
 protected function initFieldMetadataDefaultLabel(FieldMetadata $fieldMetadata)
 {
     if ($fieldMetadata->has('label')) {
         return;
     }
     $labelCode = 'label';
     $className = $fieldMetadata->getSourceClassName();
     $fieldName = $fieldMetadata->getSourceFieldName();
     if (!$fieldMetadata->isDefinedBySourceEntity()) {
         $fieldName = null;
         if ($fieldMetadata->isCollection()) {
             $labelCode = 'plural_label';
         }
     }
     $entityConfig = $this->entityConfigHelper->getConfig(self::CONFIG_ENTITY_SCOPE, $className, $fieldName);
     if ($entityConfig) {
         $fieldMetadata->set('label', $entityConfig->get($labelCode));
     }
 }
Ejemplo n.º 11
0
 /**
  * @param FieldMetadata $metadata
  * @return string
  */
 protected function getPropertyPath(FieldMetadata $metadata)
 {
     return $metadata->has('property_path') ? $metadata->get('property_path') : $metadata->getFieldName();
 }
Ejemplo n.º 12
0
 /**
  * @param FieldMetadata $fieldMetadata
  */
 public function addFieldMetadata(FieldMetadata $fieldMetadata)
 {
     $fieldMetadata->setEntityMetadata($this);
     $this->fieldsMetadata[$fieldMetadata->getFieldName()] = $fieldMetadata;
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function supports($entity, FieldMetadata $metadata)
 {
     return $this->taggableHelper->isTaggable($entity) && $metadata->getSourceClassName() === 'Oro\\Bundle\\TagBundle\\Entity\\Tag';
 }