/**
  * @param array $fields
  * @param array $configValues
  * @param array $expected
  *
  * @dataProvider fieldsDataProvider
  */
 public function testGetFields(array $fields, array $configValues, array $expected)
 {
     $entity = new \StdClass();
     foreach ($fields as $field) {
         /** @var ConfigInterface $field */
         $fieldId = $field->getId();
         /** @var FieldConfigId $fieldId */
         $fieldName = $fieldId->getFieldName();
         $entity->{$fieldName} = $fieldName;
     }
     $this->configProvider->expects($this->once())->method('filter')->will($this->returnValue($fields));
     $config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $this->configProvider->expects($this->any())->method('getConfigById')->will($this->returnValue($config));
     foreach ($configValues as $key => $configValue) {
         $config->expects($this->at($key))->method('get')->will($this->returnCallback(function ($value, $strict, $default) use($configValue) {
             if (!is_null($configValue)) {
                 return $configValue;
             }
             return $default;
         }));
     }
     $this->dispatcher->expects($this->exactly(sizeof($fields)))->method('dispatch');
     $rows = $this->extension->getFields($entity);
     $this->assertEquals(json_encode($expected), json_encode($rows));
 }
 /**
  * Makes sure the class hierarchy was loaded
  */
 protected function ensureHierarchyInitialized()
 {
     if (null === $this->hierarchy) {
         $this->hierarchy = [];
         $entityConfigs = $this->extendConfigProvider->getConfigs();
         foreach ($entityConfigs as $entityConfig) {
             if ($entityConfig->in('state', [ExtendScope::STATE_NEW, ExtendScope::STATE_DELETE])) {
                 continue;
             }
             if ($entityConfig->is('is_deleted')) {
                 continue;
             }
             $className = $entityConfig->getId()->getClassName();
             $parents = [];
             $this->loadParents($parents, $className);
             if (empty($parents)) {
                 continue;
             }
             // remove proxies if they are in list of parents
             $parents = array_filter($parents, function ($parentClassName) {
                 return strpos($parentClassName, ExtendHelper::ENTITY_NAMESPACE) !== 0;
             });
             if (empty($parents)) {
                 continue;
             }
             $this->hierarchy[$className] = $parents;
         }
     }
 }
示例#3
0
 /**
  * Generate doctrine proxy classes for extended entities for the given entity manager
  *
  * @param EntityManager $em
  */
 protected function generateEntityManagerProxies(EntityManager $em)
 {
     $isAutoGenerated = $em->getConfiguration()->getAutoGenerateProxyClasses();
     if (!$isAutoGenerated) {
         $proxyDir = $em->getConfiguration()->getProxyDir();
         if (!empty($this->cacheDir) && $this->kernelCacheDir !== $this->cacheDir && strpos($proxyDir, $this->kernelCacheDir) === 0) {
             $proxyDir = $this->cacheDir . substr($proxyDir, strlen($this->kernelCacheDir));
         }
         $metadataFactory = $em->getMetadataFactory();
         $proxyFactory = $em->getProxyFactory();
         $extendConfigs = $this->extendConfigProvider->getConfigs(null, true);
         foreach ($extendConfigs as $extendConfig) {
             if (!$extendConfig->is('is_extend')) {
                 continue;
             }
             if ($extendConfig->in('state', [ExtendScope::STATE_NEW])) {
                 continue;
             }
             $entityClass = $extendConfig->getId()->getClassName();
             $proxyFileName = $proxyDir . DIRECTORY_SEPARATOR . '__CG__' . str_replace('\\', '', $entityClass) . '.php';
             $metadata = $metadataFactory->getMetadataFor($entityClass);
             $proxyFactory->generateProxyClasses([$metadata], $proxyDir);
             clearstatcache(true, $proxyFileName);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function resolve(Route $route, RouteCollectionAccessor $routes)
 {
     if ($route->getOption('group') !== self::ROUTE_GROUP) {
         return;
     }
     if ($this->hasAttribute($route, self::ACTIVITY_PLACEHOLDER)) {
         $activities = array_map(function (ConfigInterface $config) {
             // convert to entity alias
             return $this->entityAliasResolver->getPluralAlias($config->getId()->getClassName());
         }, $this->groupingConfigProvider->filter(function (ConfigInterface $config) {
             // filter activity entities
             $groups = $config->get('groups');
             return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
         }));
         if (!empty($activities)) {
             $activities = $this->adjustRoutes($route, $routes, $activities);
             if (!empty($activities)) {
                 $route->setRequirement(self::ACTIVITY_ATTRIBUTE, implode('|', $activities));
             }
         }
         $this->completeRouteRequirements($route);
     } elseif ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) {
         $this->completeRouteRequirements($route);
     }
 }
 /**
  * Handle prePersist.
  *
  * @param LifecycleEventArgs $args
  * @throws \LogicException when getOwner method isn't implemented for entity with ownership type
  */
 public function prePersist(LifecycleEventArgs $args)
 {
     $token = $this->getSecurityContext()->getToken();
     if (!$token) {
         return;
     }
     $user = $token->getUser();
     if (!$user) {
         return;
     }
     $entity = $args->getEntity();
     if ($this->configProvider->hasConfig(get_class($entity))) {
         $config = $this->configProvider->getConfig(get_class($entity));
         $ownerType = $config->get('owner_type');
         if ($ownerType && $ownerType !== OwnershipType::OWNER_TYPE_NONE) {
             if (!method_exists($entity, 'getOwner')) {
                 throw new \LogicException(sprintf('Method getOwner must be implemented for %s entity', get_class($entity)));
             }
             if (!$entity->getOwner()) {
                 /**
                  * Automatically set current user as record owner
                  */
                 if (OwnershipType::OWNER_TYPE_USER == $ownerType && method_exists($entity, 'setOwner')) {
                     $entity->setOwner($user);
                 }
             }
         }
     }
 }
示例#6
0
 protected function getEntityChoiceList($entityClassName, $relationType)
 {
     $configManager = $this->configProvider->getConfigManager();
     $choices = array();
     if ($this->targetEntity) {
         $entityIds = array($this->configProvider->getId($this->targetEntity));
     } else {
         $entityIds = $configManager->getIds('extend');
     }
     if (in_array($relationType, array('oneToMany', 'manyToMany'))) {
         $entityIds = array_filter($entityIds, function (EntityConfigId $configId) use($configManager) {
             $config = $configManager->getConfig($configId);
             return $config->is('is_extend');
         });
     }
     $entityIds = array_filter($entityIds, function (EntityConfigId $configId) use($configManager) {
         $config = $configManager->getConfig($configId);
         return $config->is('is_extend', false) || !$config->is('state', ExtendScope::STATE_NEW);
     });
     foreach ($entityIds as $entityId) {
         $className = $entityId->getClassName();
         if ($className != $entityClassName) {
             list($moduleName, $entityName) = ConfigHelper::getModuleAndEntityNames($className);
             $choices[$className] = $moduleName . ':' . $entityName;
         }
     }
     return $choices;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (empty($options['data_class'])) {
         return;
     }
     $className = $options['data_class'];
     if (!$this->doctrineHelper->isManageableEntity($className)) {
         return;
     }
     if (!$this->entityConfigProvider->hasConfig($className)) {
         return;
     }
     $uniqueKeys = $this->entityConfigProvider->getConfig($className)->get('unique_key');
     if (empty($uniqueKeys)) {
         return;
     }
     /* @var \Symfony\Component\Validator\Mapping\ClassMetadata $validatorMetadata */
     $validatorMetadata = $this->validator->getMetadataFor($className);
     foreach ($uniqueKeys['keys'] as $uniqueKey) {
         $fields = $uniqueKey['key'];
         $labels = array_map(function ($fieldName) use($className) {
             $label = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
             return $this->translator->trans($label);
         }, $fields);
         $constraint = new UniqueEntity(['fields' => $fields, 'errorPath' => '', 'message' => $this->translator->transChoice('oro.entity.validation.unique_field', sizeof($fields), ['%field%' => implode(', ', $labels)])]);
         $validatorMetadata->addConstraint($constraint);
     }
 }
示例#8
0
 /**
  * @param string          $dataClass Parent entity class name
  * @param File|Attachment $entity    File entity
  * @param string          $fieldName Field name where new file/image field was added
  *
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public function validate($dataClass, $entity, $fieldName = '')
 {
     /** @var Config $entityAttachmentConfig */
     if ($fieldName === '') {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass);
         $mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes'));
         if (!$mimeTypes) {
             $mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types')));
         }
     } else {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName);
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $entityAttachmentConfig->getId();
         if ($fieldConfigId->getFieldType() === 'file') {
             $configValue = 'upload_file_mime_types';
         } else {
             $configValue = 'upload_image_mime_types';
         }
         $mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue));
     }
     $fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024;
     foreach ($mimeTypes as $id => $value) {
         $mimeTypes[$id] = trim($value);
     }
     return $this->validator->validate($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes])]);
 }
 /**
  * Handle prePersist.
  *
  * @param LifecycleEventArgs $args
  * @throws \LogicException when getOwner method isn't implemented for entity with ownership type
  */
 public function prePersist(LifecycleEventArgs $args)
 {
     $token = $this->getSecurityContext()->getToken();
     if (!$token) {
         return;
     }
     $user = $token->getUser();
     if (!$user) {
         return;
     }
     $entity = $args->getEntity();
     $className = ClassUtils::getClass($entity);
     if ($this->configProvider->hasConfig($className)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $config = $this->configProvider->getConfig($className);
         $ownerType = $config->get('owner_type');
         $ownerFieldName = $config->get('owner_field_name');
         // set default owner for organization and user owning entities
         if ($ownerType && in_array($ownerType, [OwnershipType::OWNER_TYPE_ORGANIZATION, OwnershipType::OWNER_TYPE_USER]) && !$accessor->getValue($entity, $ownerFieldName)) {
             $owner = null;
             if (OwnershipType::OWNER_TYPE_USER == $ownerType) {
                 $owner = $user;
             } elseif (OwnershipType::OWNER_TYPE_ORGANIZATION == $ownerType && $token instanceof OrganizationContextTokenInterface) {
                 $owner = $token->getOrganizationContext();
             }
             $accessor->setValue($entity, $ownerFieldName, $owner);
         }
         //set organization
         $this->setDefaultOrganization($token, $config, $entity);
     }
 }
示例#10
0
 /**
  * @param ConfigureMenuEvent $event
  */
 public function onNavigationConfigure(ConfigureMenuEvent $event)
 {
     /** @var ItemInterface $reportsMenuItem */
     $reportsMenuItem = $event->getMenu()->getChild('reports_tab');
     if ($reportsMenuItem && $this->securityFacade->hasLoggedUser()) {
         $qb = $this->em->getRepository('OroReportBundle:Report')->createQueryBuilder('report')->orderBy('report.name', 'ASC');
         $reports = $this->aclHelper->apply($qb)->execute();
         if (!empty($reports)) {
             $this->addDivider($reportsMenuItem);
             $reportMenuData = [];
             foreach ($reports as $report) {
                 $config = $this->entityConfigProvider->getConfig($report->getEntity());
                 if ($this->checkAvailability($config)) {
                     $entityLabel = $config->get('plural_label');
                     if (!isset($reportMenuData[$entityLabel])) {
                         $reportMenuData[$entityLabel] = [];
                     }
                     $reportMenuData[$entityLabel][$report->getId()] = $report->getName();
                 }
             }
             ksort($reportMenuData);
             $this->buildReportMenu($reportsMenuItem, $reportMenuData);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var ConfigContext $context */
     $definition = $context->getResult();
     if (empty($definition)) {
         // an entity configuration does not exist
         return;
     }
     $entityClass = $context->getClassName();
     if (!isset($definition[ConfigUtil::LABEL])) {
         $entityName = $this->entityClassNameProvider->getEntityClassName($entityClass);
         if ($entityName) {
             $definition[ConfigUtil::LABEL] = $entityName;
         }
     }
     if (!isset($definition[ConfigUtil::PLURAL_LABEL])) {
         $entityPluralName = $this->entityClassNameProvider->getEntityClassPluralName($entityClass);
         if ($entityPluralName) {
             $definition[ConfigUtil::PLURAL_LABEL] = $entityPluralName;
         }
     }
     if (!isset($definition[ConfigUtil::DESCRIPTION]) && $this->entityConfigProvider->hasConfig($entityClass)) {
         $definition[ConfigUtil::DESCRIPTION] = new Label($this->entityConfigProvider->getConfig($entityClass)->get('description'));
     }
     $context->setResult($definition);
 }
 /**
  * Return available in template variables
  *
  * @param string $entityName
  * @return array
  */
 public function getTemplateVariables($entityName)
 {
     $userClassName = $this->getUser() ? get_class($this->getUser()) : false;
     $allowedData = array('entity' => array(), 'user' => array());
     $ids = $this->configProvider->getIds();
     foreach ($ids as $entityConfigId) {
         // export variables of asked entity and current user entity class
         $className = $entityConfigId->getClassName();
         if ($className == $entityName || $className == $userClassName) {
             $fields = $this->configProvider->filter(function (ConfigInterface $config) {
                 return $config->is('available_in_template');
             }, $className);
             $fields = array_values(array_map(function (ConfigInterface $field) {
                 return $field->getId()->getFieldName();
             }, $fields));
             switch ($className) {
                 case $entityName:
                     $allowedData['entity'] = $fields;
                     break;
                 case $userClassName:
                     $allowedData['user'] = $fields;
                     break;
             }
             if ($entityName == $userClassName) {
                 $allowedData['user'] = $allowedData['entity'];
             }
         }
     }
     return $allowedData;
 }
示例#13
0
 /**
  * Checks if the entity can has notes
  *
  * @param object $entity
  * @return bool
  */
 public function isAttachmentAssociationEnabled($entity)
 {
     if (null === $entity || !is_object($entity)) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->attachmentConfigProvider->hasConfig($className) && $this->attachmentConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(AttachmentScope::ATTACHMENT, ExtendHelper::buildAssociationName($className));
 }
 /**
  * Checks if the entity can have comments
  *
  * @param object|null $entity
  *
  * @return bool
  */
 public function isApplicable($entity)
 {
     if (!is_object($entity) || !$this->doctrineHelper->isManageableEntity($entity) || !$this->securityFacade->isGranted('oro_comment_view')) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->commentConfigProvider->hasConfig($className) && $this->commentConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Comment::ENTITY_NAME, ExtendHelper::buildAssociationName($className));
 }
示例#15
0
 /**
  * @param mixed $entity
  * @param bool  $show
  *
  * @return bool
  */
 public function isEntityAuditable($entity, $show)
 {
     if ($show || !is_object($entity)) {
         return $show;
     }
     $className = ClassUtils::getClass($entity);
     return $this->configProvider->hasConfig($className) && $this->configProvider->getConfig($className)->is('auditable');
 }
 /**
  * {@inheritdoc}
  */
 public function supports(array $schema)
 {
     if (!$this->groupingConfigProvider->hasConfig($schema['class'])) {
         return false;
     }
     $groups = $this->groupingConfigProvider->getConfig($schema['class'])->get('groups');
     return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups);
 }
 /**
  * Adds entities to $result
  *
  * @param array $result
  */
 protected function addEntities(array &$result)
 {
     // only configurable entities are supported
     $configs = $this->entityConfigProvider->getConfigs();
     foreach ($configs as $config) {
         $this->addEntity($result, $config->getId()->getClassName(), $config->get('label'), $config->get('plural_label'), $config->get('icon'));
     }
 }
示例#18
0
 /**
  * Checks if the entity can be shared
  *
  * @param object $entity
  * @return bool
  */
 public function isShareEnabled($entity)
 {
     if (null === $entity || !is_object($entity)) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->securityFacade->isGranted('SHARE', $entity) && $this->configProvider->hasConfig($className) && $this->configProvider->getConfig($className)->get('share_scopes');
 }
示例#19
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->config = $this->configProvider->getConfigById($options['config_id']);
     $this->formFactory = $builder->getFormFactory();
     $builder->add('target_entity', new TargetType($this->configProvider, $options['config_id']), ['constraints' => [new Assert\NotBlank()]]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, array($this, 'preSubmitData'));
     $builder->addEventListener(FormEvents::PRE_SUBMIT, array($this, 'preSubmitData'));
 }
示例#20
0
 /**
  * Checks if the entity can has notes
  *
  * @param object $entity
  * @return bool
  */
 public function isNoteAssociationEnabled($entity)
 {
     if (null === $entity || !is_object($entity)) {
         return false;
     }
     $className = ClassUtils::getClass($entity);
     return $this->noteConfigProvider->hasConfig($className) && $this->noteConfigProvider->getConfig($className)->is('enabled') && $this->entityConfigProvider->hasConfig(Note::ENTITY_NAME, ExtendHelper::buildAssociationName($className));
 }
 /**
  * Gets translated field name by its name
  *
  * @param string $className
  * @param string $fieldName
  *
  * @return string
  */
 protected function getFieldLabel($className, $fieldName)
 {
     if (!$this->entityConfigProvider->hasConfig($className, $fieldName)) {
         return $fieldName;
     }
     $fieldLabel = $this->entityConfigProvider->getConfig($className, $fieldName)->get('label');
     return $this->translator->trans($fieldLabel);
 }
 /**
  * @param $entity
  * @return string
  */
 public function getOwnerType($entity)
 {
     $ownerClassName = ClassUtils::getRealClass(get_class($entity));
     if (!$this->configProvider->hasConfig($ownerClassName)) {
         return;
     }
     $config = $this->configProvider->getConfig($ownerClassName)->all();
     return $config['owner_type'];
 }
示例#23
0
 /**
  * @param object $entity
  * @return string
  */
 public function getOwnerType($entity)
 {
     $ownerClassName = ClassUtils::getRealClass($entity);
     if (!$this->configProvider->hasConfig($ownerClassName)) {
         return null;
     }
     $config = $this->configProvider->getConfig($ownerClassName);
     return $config->get('owner_type');
 }
示例#24
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testCreateEntityMetadataByClass()
 {
     $this->doctrineHelper->expects($this->once())->method('getMetadataFor')->with(self::CLASS_NAME)->will($this->returnValue($this->classMetadata));
     $this->entityExtendConfigProvider->expects($this->any())->method('getConfigs')->with(static::CLASS_NAME)->will($this->returnValue([]));
     $this->classMetadata->name = static::CLASS_NAME;
     $this->classMetadata->expects($this->any())->method('getIdentifierFieldNames')->will($this->returnValue(['id']));
     // Test creation of entity metadata
     $entityMetadataCallIndex = 0;
     $entityMetadata = $this->createEntityMetadata();
     $metadataFactoryCallIndex = 0;
     $this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createEntityMetadata')->with([], $this->isType('array'))->will($this->returnValue($entityMetadata));
     // Test adding doctrine fields
     $doctrineFieldNames = ['id', 'foo_field', 'bar_field'];
     $doctrineFieldNamesWithoutId = ['foo_field', 'bar_field'];
     $idFieldNames = ['id'];
     $this->classMetadata->expects($this->any())->method('getIdentifierFieldNames')->will($this->returnValue($idFieldNames));
     $this->classMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($doctrineFieldNames));
     $this->classMetadata->expects($this->any())->method('getFieldMapping')->will($this->returnCallback(function ($fieldName) {
         return ['fieldName' => $fieldName];
     }));
     foreach ($doctrineFieldNamesWithoutId as $fieldName) {
         $fieldMapping = ['fieldName' => $fieldName];
         $fieldMetadata = $this->createFieldMetadata();
         $this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with(['field_name' => $fieldName], $fieldMapping)->will($this->returnValue($fieldMetadata));
         $entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
     }
     // Test adding doctrine associations
     $associationMappings = ['foo_association' => ['foo' => 'bar'], 'bar_association' => ['bar' => 'baz']];
     $this->classMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue(array_keys($associationMappings)));
     $this->classMetadata->expects($this->any())->method('getAssociationMapping')->will($this->returnCallback(function ($association) use($associationMappings) {
         return $associationMappings[$association];
     }));
     foreach ($associationMappings as $fieldName => $associationMapping) {
         $fieldMetadata = $this->createFieldMetadata();
         $this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with(['field_name' => $fieldName], $associationMapping)->will($this->returnValue($fieldMetadata));
         $entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
     }
     // Test adding doctrine inverse associations
     $allMetadata = [self::CLASS_NAME => $this->classMetadata, 'Namespace\\FooEntity' => $fooClassMetadata = $this->createClassMetadata(), 'Namespace\\BarEntity' => $barClassMetadata = $this->createClassMetadata(), 'Namespace\\FooBarEntity' => $fooBarClassMetadata = $this->createClassMetadata()];
     $expectedClassesData = ['Namespace\\FooEntity' => ['associationMappings' => ['foo_association' => ['foo' => 'bar', 'type' => ClassMetadataInfo::ONE_TO_MANY]], 'expectedFields' => ['foo_association' => ['field_name' => 'Namespace_FooEntity_foo_association', 'merge_modes' => [MergeModes::UNITE], 'source_field_name' => 'foo_association', 'source_class_name' => 'Namespace\\FooEntity']]], 'Namespace\\BarEntity' => ['associationMappings' => ['bar_association' => ['bar' => 'baz', 'type' => ClassMetadataInfo::ONE_TO_MANY], 'skipped_many_to_many' => ['type' => ClassMetadataInfo::MANY_TO_MANY], 'skipped_mapped_by' => ['mappedBy' => self::CLASS_NAME]], 'expectedFields' => ['bar_association' => ['field_name' => 'Namespace_BarEntity_bar_association', 'merge_modes' => [MergeModes::UNITE], 'source_field_name' => 'bar_association', 'source_class_name' => 'Namespace\\BarEntity']]], 'Namespace\\FooBarEntity' => ['associationMappings' => ['bar_association' => ['bar' => 'baz', 'type' => ClassMetadataInfo::ONE_TO_ONE]], 'expectedFields' => ['bar_association' => ['field_name' => 'Namespace_FooBarEntity_bar_association', 'merge_modes' => [MergeModes::REPLACE], 'source_field_name' => 'bar_association', 'source_class_name' => 'Namespace\\FooBarEntity']]]];
     $this->doctrineHelper->expects($this->once())->method('getAllMetadata')->will($this->returnValue(array_values($allMetadata)));
     foreach ($expectedClassesData as $className => $expectedData) {
         $metadata = $allMetadata[$className];
         $metadata->expects($this->once())->method('getName')->will($this->returnValue($className));
         $metadata->expects($this->once())->method('getAssociationsByTargetClass')->with(self::CLASS_NAME)->will($this->returnValue($expectedData['associationMappings']));
         foreach ($expectedData['expectedFields'] as $fieldName => $expectedOptions) {
             $expectedAssociationMapping = $expectedData['associationMappings'][$fieldName];
             $expectedAssociationMapping['mappedBySourceEntity'] = false;
             $fieldMetadata = $this->createFieldMetadata();
             $this->metadataFactory->expects($this->at($metadataFactoryCallIndex++))->method('createFieldMetadata')->with($expectedOptions, $expectedAssociationMapping)->will($this->returnValue($fieldMetadata));
             $entityMetadata->expects($this->at($entityMetadataCallIndex++))->method('addFieldMetadata')->with($fieldMetadata);
         }
     }
     // Test event dispatcher
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(MergeEvents::BUILD_METADATA, new EntityMetadataEvent($entityMetadata));
     $this->assertEquals($entityMetadata, $this->metadataBuilder->createEntityMetadataByClass(self::CLASS_NAME));
 }
示例#25
0
 /**
  * @param ClassMetadataBuilder $metadataBuilder
  * @param string               $className
  */
 public function build(ClassMetadataBuilder $metadataBuilder, $className)
 {
     $extendConfig = $this->extendConfigProvider->getConfig($className);
     foreach ($this->builders as $builder) {
         if ($builder->supports($extendConfig)) {
             $builder->build($metadataBuilder, $extendConfig);
         }
     }
 }
示例#26
0
 public function testIsNoteAssociationEnabled()
 {
     $config = new Config(new EntityConfigId('note', static::TEST_ENTITY_REFERENCE));
     $config->set('enabled', true);
     $this->noteConfigProvider->expects($this->once())->method('hasConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue(true));
     $this->noteConfigProvider->expects($this->once())->method('getConfig')->with(static::TEST_ENTITY_REFERENCE)->will($this->returnValue($config));
     $this->entityConfigProvider->expects($this->once())->method('hasConfig')->with(Note::ENTITY_NAME, ExtendHelper::buildAssociationName(static::TEST_ENTITY_REFERENCE))->will($this->returnValue(true));
     $this->assertTrue($this->filter->isNoteAssociationEnabled(new TestEntity(1)));
 }
 /**
  * {@inheritdoc}
  */
 public function beforeValueRender(ValueRenderEvent $event)
 {
     $fieldConfig = $this->configProvider->getConfigById($event->getFieldConfigId());
     $contactInformationType = $fieldConfig->get('contact_information');
     // if some contact information type is defined -- applies proper template for its value
     if (null !== $contactInformationType && isset($this->contactInformationMap[$contactInformationType])) {
         $event->setFieldViewValue(['value' => $event->getFieldValue(), 'entity' => $event->getEntity(), 'template' => $this->contactInformationMap[$contactInformationType]]);
     }
 }
 protected function prepareConfigProvider(array $configValues, $className)
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|ConfigIdInterface $configId */
     $configId = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $entityConfig = new Config($configId);
     $entityConfig->setValues($configValues);
     $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo($className))->will($this->returnValue(true));
     $this->configProvider->expects($this->once())->method('getConfig')->with($this->equalTo($className))->will($this->returnValue($entityConfig));
 }
 /**
  * @param object $entity
  *
  * @return ConfigInterface[]
  */
 protected function getEntityActivityContactFields($entity)
 {
     $fields = array_keys(ActivityScope::$fieldsConfiguration);
     return $this->extendProvider->filter(function (ConfigInterface $config) use($fields) {
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $config->getId();
         return in_array($fieldConfigId->getFieldName(), $fields);
     }, ClassUtils::getClass($entity));
 }
示例#30
0
 /**
  * @param Tag $tag
  *
  * @return array ['' => [count], $alias => [count, icon, label, class => true]]
  */
 public function getTagEntitiesStatistic(Tag $tag)
 {
     $groupedResult = $this->getGroupedTagEntities($tag);
     return array_reduce($groupedResult, function ($result, array $entityResult) {
         $result['']['count'] += $entityResult['cnt'];
         $entityClass = $entityResult['entityClass'];
         $alias = $this->entityAliasResolver->getAlias($entityClass);
         $result[$alias] = ['count' => $entityResult['cnt'], 'icon' => $this->entityConfigProvider->getConfig($entityClass)->get('icon'), 'label' => $this->entityConfigProvider->getConfig($entityClass)->get('plural_label'), 'class' => true];
         return $result;
     }, ['' => ['count' => 0]]);
 }