/** * @param FieldMetadata $fieldMetadata * @return array */ protected function initMergeModes(FieldMetadata $fieldMetadata) { $fieldMetadata->addMergeMode(MergeModes::REPLACE); if ($fieldMetadata->isCollection()) { $fieldMetadata->addMergeMode(MergeModes::UNITE); } }
/** * @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(); } }
/** * 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); } }
/** * @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)); }
/** * 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); } }
/** * 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); } } }
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()); }
/** * {@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); }
/** * @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)); } }
/** * @param FieldMetadata $metadata * @return string */ protected function getPropertyPath(FieldMetadata $metadata) { return $metadata->has('property_path') ? $metadata->get('property_path') : $metadata->getFieldName(); }
/** * @param FieldMetadata $fieldMetadata */ public function addFieldMetadata(FieldMetadata $fieldMetadata) { $fieldMetadata->setEntityMetadata($this); $this->fieldsMetadata[$fieldMetadata->getFieldName()] = $fieldMetadata; }
/** * {@inheritdoc} */ public function supports($entity, FieldMetadata $metadata) { return $this->taggableHelper->isTaggable($entity) && $metadata->getSourceClassName() === 'Oro\\Bundle\\TagBundle\\Entity\\Tag'; }