/**
  * {@inheritdoc}
  */
 protected function getChoices($entityName, $withRelations, $withVirtualFields)
 {
     $choiceFields = [];
     $choiceRelations = [];
     $idFieldNames = $this->doctrineHelper->getEntityIdentifierFieldNames($entityName);
     foreach ($this->getEntityFields($entityName, $withRelations, $withVirtualFields) as $fieldName => $field) {
         $formConfig = $this->formConfigProvider->getConfig($entityName, $fieldName);
         if ($formConfig->is('is_enabled', false) || in_array($fieldName, $idFieldNames)) {
             // field is not enabled for displaying in forms
             // or field is entity identifier
             continue;
         }
         if (!isset($field['relation_type'])) {
             $choiceFields[$fieldName] = $field['label'];
         } elseif (!in_array($field['relation_type'], RelationType::$toManyRelations)) {
             // enable only mass update for *-to-one relations
             $choiceRelations[$fieldName] = $field['label'];
         }
     }
     if (empty($choiceRelations)) {
         return $choiceFields;
     }
     $choices = [];
     if (!empty($choiceFields)) {
         $choices[$this->translator->trans('oro.entity.form.entity_fields')] = $choiceFields;
     }
     $choices[$this->translator->trans('oro.entity.form.entity_related')] = $choiceRelations;
     return $choices;
 }
 /**
  * @param bool $withRelations
  *
  * @dataProvider testDataProvider
  */
 public function testBuildFormRegularGuesser($withRelations)
 {
     $entityName = 'Test\\Entity';
     $this->doctrineHelperMock->expects($this->once())->method('getEntityIdentifierFieldNames')->with($entityName)->willReturn(['id']);
     $fields = [['name' => 'oneField', 'type' => 'string', 'label' => 'One field'], ['name' => 'anotherField', 'type' => 'string', 'label' => 'Another field']];
     if ($withRelations) {
         $fields[] = ['name' => 'relField', 'relation_type' => 'ref-one', 'label' => 'Many to One field'];
     }
     $this->entityFieldMock->expects($this->once())->method('getFields')->willReturn($fields);
     $this->formConfigMock->expects($this->at(0))->method('getConfig')->with($entityName, 'oneField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'someField'), ['is_enabled' => false]));
     $this->formConfigMock->expects($this->at(1))->method('getConfig')->with($entityName, 'anotherField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'anotherField'), ['is_enabled' => true]));
     if ($withRelations) {
         $this->formConfigMock->expects($this->at(2))->method('getConfig')->with($entityName, 'relField')->willReturn(new Config(new FieldConfigId('form', $entityName, 'relField'), ['is_enabled' => true]));
         $this->translatorMock->expects($this->at(0))->method('trans')->with('oro.entity.form.entity_fields')->willReturn('Fields');
         $this->translatorMock->expects($this->at(1))->method('trans')->with('oro.entity.form.entity_related')->willReturn('Relations');
     }
     $form = $this->factory->create($this->type, null, ['entity' => $entityName, 'with_relations' => $withRelations]);
     $view = $form->createView();
     $this->assertEquals('update_field_choice', $view->vars['full_name'], 'Failed asserting that field name is correct');
     $this->assertNotEmpty($view->vars['configs']['component']);
     $this->assertEquals('entity-field-choice', $view->vars['configs']['component']);
     $this->assertEquals('update_field_choice', $form->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
     if ($withRelations) {
         $this->assertCount(2, $view->vars['choices'], 'Failed asserting that choices are grouped');
     } else {
         $this->assertCount(1, $view->vars['choices'], 'Failed asserting that choices exists');
         /** @var ChoiceView $choice */
         $choice = reset($view->vars['choices']);
         $this->assertEquals('Another field', $choice->label);
     }
 }
 /**
  * @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));
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (empty($options['data_class'])) {
         return;
     }
     $className = $options['data_class'];
     if (!$this->entityConfigProvider->hasConfig($className)) {
         return;
     }
     $config = $this->entityConfigProvider->getConfig($className);
     if (!$config->has('unique_key')) {
         return;
     }
     $uniqueKeys = $config->get('unique_key', false, ['keys' => []]);
     /* @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);
     }
 }
 /**
  * @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));
 }
 /**
  * @param string $className
  * @return bool
  */
 protected function hasFrontendOwnership($className)
 {
     if ($this->ownershipConfigProvider->hasConfig($className)) {
         $config = $this->ownershipConfigProvider->getConfig($className);
         if ($config->has('frontend_owner_type')) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 7
0
 /**
  * @param ResultRecordInterface $record
  * @return array
  */
 public function getWorkflowDefinitionPermissions(ResultRecordInterface $record)
 {
     $isActiveWorkflow = false;
     $relatedEntity = $record->getValue('entityClass');
     if ($this->configProvider->hasConfig($relatedEntity)) {
         $config = $this->configProvider->getConfig($relatedEntity);
         $isActiveWorkflow = $record->getValue('name') == $config->get('active_workflow');
     }
     $isSystem = $record->getValue('system');
     return array('activate' => !$isActiveWorkflow, 'clone' => true, 'deactivate' => $isActiveWorkflow, 'delete' => !$isSystem, 'update' => !$isSystem, 'view' => true);
 }
Ejemplo n.º 8
0
 /**
  * @param string $entityName
  * @return string|null
  */
 protected function getEntityGridName($entityName)
 {
     $gridName = null;
     if ($this->configProvider->hasConfig($entityName)) {
         $config = $this->configProvider->getConfig($entityName);
         $gridName = $config->get('grid_name');
     }
     if (!$gridName) {
         throw new \RuntimeException(sprintf('Grid not found for entity "%s"', $entityName));
     }
     return $gridName;
 }
 /**
  * {@inheritdoc}
  */
 protected function filterPrivileges(ArrayCollection $privileges, array $rootIds)
 {
     $privileges = parent::filterPrivileges($privileges, $rootIds);
     $entityPrefix = 'entity:';
     foreach ($privileges as $key => $privilege) {
         $oid = $privilege->getIdentity()->getId();
         if (strpos($oid, $entityPrefix) === 0) {
             $className = substr($oid, strlen($entityPrefix));
             if (!$this->ownershipConfigProvider->hasConfig($className)) {
                 unset($privileges[$key]);
             }
         }
     }
     return $privileges;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $fields = [];
     $className = $options['className'];
     $fieldConfigIds = $this->entityProvider->getIds($className);
     /** @var FieldConfigId $fieldConfigId */
     foreach ($fieldConfigIds as $fieldConfigId) {
         if ($fieldConfigId->getFieldType() === RelationTypeBase::TO_MANY) {
             continue;
         }
         $fieldName = $fieldConfigId->getFieldName();
         $fields[$fieldName] = $this->entityProvider->getConfig($className, $fieldName)->get('label', false, ucfirst($fieldName));
     }
     $builder->add('keys', 'collection', array('required' => true, 'type' => new UniqueKeyType($fields), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'prototype_name' => 'tag__name__', 'label' => false, 'constraints' => [new UniqueKeys()]));
 }
 /**
  * @param object $object
  *
  * @return array
  */
 protected function getApplicableRelations($object)
 {
     $result = [];
     $className = ClassUtils::getClass($object);
     if (!$this->extendConfigProvider->hasConfig($className)) {
         return $result;
     }
     $extendConfig = $this->extendConfigProvider->getConfig($className);
     $relations = $extendConfig->get('relation');
     if (empty($relations)) {
         return $result;
     }
     $targetEntities = $this->getTargetEntities();
     foreach ($relations as $relation) {
         if (empty($relation['owner'])) {
             continue;
         }
         /** @var FieldConfigId $fieldId */
         $fieldId = $relation['field_id'];
         if ($fieldId->getFieldType() !== 'manyToOne') {
             continue;
         }
         $relatedEntityClass = $relation['target_entity'];
         if (!in_array($relatedEntityClass, $targetEntities)) {
             continue;
         }
         if (!isset($result[$relatedEntityClass])) {
             $result[$relatedEntityClass] = [];
         }
         $result[$relatedEntityClass][] = $fieldId->getFieldName();
     }
     return $result;
 }
 /**
  * @param null|string $entityName
  *
  * @return bool
  */
 public function isMassActionEnabled($entityName)
 {
     $isEnabled = false;
     if ($entityName && $this->gridConfigProvider->hasConfig($entityName)) {
         $isEnabled = $this->gridConfigProvider->getConfig($entityName)->is('update_mass_action_enabled');
     } else {
         $this->logger->debug("Update Mass Action: not configured for " . $entityName);
     }
     if ($isEnabled && $this->securityFacade->isGranted('EDIT', 'entity:' . $entityName)) {
         $isEnabled = true;
     } elseif ($isEnabled) {
         $this->logger->debug("Update Mass Action: not allowed to modify the entity of class " . $entityName);
         $isEnabled = false;
     }
     return $isEnabled;
 }
 /**
  * @param string $entity
  * @return bool
  */
 protected function isShowWorkflowStep($entity)
 {
     if ($this->configProvider->hasConfig($entity)) {
         $config = $this->configProvider->getConfig($entity);
         return $config->has('show_step_in_grid') && $config->is('show_step_in_grid');
     }
     return false;
 }
Ejemplo n.º 14
0
 /**
  * {@inheritDoc}
  */
 public function guessType($class, $property)
 {
     $metadata = $this->getMetadataForClass($class);
     if (!$metadata || !$this->formConfigProvider->hasConfig($class, $property)) {
         return $this->createDefaultTypeGuess();
     }
     $formConfig = $this->formConfigProvider->getConfig($class, $property);
     $isSingleValuedAssoc = $property && $metadata->hasAssociation($property) && $metadata->isSingleValuedAssociation($property);
     $hasNoFormType = !$formConfig->has('form_type');
     if ($hasNoFormType && $isSingleValuedAssoc) {
         // try to find form config for target class
         $guess = $this->guessType($metadata->getAssociationTargetClass($property), null);
     } elseif ($hasNoFormType) {
         $guess = $this->createDefaultTypeGuess();
     } else {
         $guess = $this->getTypeGuess($formConfig, $class, $property);
     }
     return $guess;
 }
Ejemplo n.º 15
0
 /**
  * Get Active Workflow that is applicable to entity class
  *
  * @param string $entityClass
  * @return Workflow|null
  */
 public function getActiveWorkflowByEntityClass($entityClass)
 {
     if ($this->configProvider->hasConfig($entityClass)) {
         $entityConfig = $this->configProvider->getConfig($entityClass);
         $activeWorkflowName = $entityConfig->get('active_workflow');
         if ($activeWorkflowName) {
             return $this->getWorkflow($activeWorkflowName, false);
         }
     }
     return null;
 }
Ejemplo n.º 16
0
 /**
  * Get workflow definition related entities.
  *
  * @throws MissedRequiredOptionException
  * @return array
  */
 public function getRelatedEntitiesChoice()
 {
     if (!$this->entityName) {
         throw new MissedRequiredOptionException('Entity name is required.');
     }
     if (empty($this->relatedEntities)) {
         $qb = $this->entityManager->createQueryBuilder();
         $qb->select('entity.relatedEntity')->from($this->entityName, 'entity')->distinct('entity.relatedEntity');
         $result = (array) $qb->getQuery()->getArrayResult();
         foreach ($result as $value) {
             $className = $value['relatedEntity'];
             $label = $className;
             if ($this->configProvider->hasConfig($className)) {
                 $config = $this->configProvider->getConfig($className);
                 $label = $this->translator->trans($config->get('label'));
             }
             $this->relatedEntities[$className] = $label;
         }
     }
     return $this->relatedEntities;
 }
Ejemplo n.º 17
0
 /**
  * @param array $options
  * @param string $class
  * @param string|null $field
  * @param bool $multiple
  * @return array
  */
 protected function addLabelOption(array $options, $class, $field = null, $multiple = false)
 {
     if (array_key_exists('label', $options) || !$this->entityConfigProvider->hasConfig($class, $field)) {
         return $options;
     }
     $entityConfig = $this->entityConfigProvider->getConfig($class, $field);
     $labelOption = $multiple ? 'plural_label' : 'label';
     if ($entityConfig->has($labelOption)) {
         $options['label'] = $entityConfig->get($labelOption);
     }
     return $options;
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  */
 public function guessType($class, $property)
 {
     $metadata = $this->getMetadataForClass($class);
     if (!$metadata) {
         return $this->createDefaultTypeGuess();
     }
     if (!$this->formConfigProvider->hasConfig($class, $property)) {
         return $this->createDefaultTypeGuess();
     }
     $formConfig = $this->formConfigProvider->getConfig($class, $property);
     if (!$formConfig->has('form_type')) {
         // try to find form config for target class
         if ($property && $metadata->hasAssociation($property) && $metadata->isSingleValuedAssociation($property)) {
             return $this->guessType($metadata->getAssociationTargetClass($property), null);
         }
         return $this->createDefaultTypeGuess();
     }
     $formType = $formConfig->get('form_type');
     $formOptions = $formConfig->has('form_options') ? $formConfig->get('form_options') : array();
     $formOptions = $this->addLabelOption($formOptions, $class, $property);
     return $this->createTypeGuess($formType, $formOptions);
 }
 public function testWarmUpCacheFilterConfigsByScope()
 {
     $config1 = new Config(new EntityConfigId('ownership', 'AcmeBundle\\Entity\\User'));
     $config2 = new Config(new EntityConfigId('ownership', 'AcmeBundle\\Entity\\Account'));
     $this->configProvider->expects($this->once())->method('getConfigs')->willReturn([$config1, $config2]);
     $this->securityConfigProvider->expects($this->atLeastOnce())->method('hasConfig')->willReturn(true);
     $securityConfig1 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $securityConfig1->expects($this->once())->method('get')->with('group_name')->willReturn('');
     $securityConfig2 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $securityConfig2->expects($this->once())->method('get')->with('group_name')->willReturn('commerce');
     $this->securityConfigProvider->expects($this->atLeastOnce())->method('getConfig')->will($this->onConsecutiveCalls($securityConfig1, $securityConfig2));
     $this->cache->expects($this->once())->method('fetch')->with($this->equalTo('AcmeBundle\\Entity\\Account'));
     $this->provider->warmUpCache();
 }
Ejemplo n.º 20
0
 /**
  * Return "false" if can't find config for field, "null" if field type is unknown for given field
  * or array with config data for given field
  *
  * @param ClassMetadata $metadata
  * @param $field
  * @return array|bool
  */
 protected function guessAttributeParametersScalarField(ClassMetadata $metadata, $field)
 {
     if ($metadata->hasField($field)) {
         $doctrineType = $metadata->getTypeOfField($field);
         if (!isset($this->doctrineTypeMapping[$doctrineType])) {
             return null;
         }
         return $this->formatResult($this->getLabel($metadata->getName(), $field), $this->doctrineTypeMapping[$doctrineType]['type'], $this->doctrineTypeMapping[$doctrineType]['options']);
     } elseif ($this->entityConfigProvider->hasConfig($metadata->getName(), $field)) {
         $entityConfig = $this->entityConfigProvider->getConfig($metadata->getName(), $field);
         $fieldType = $entityConfig->getId()->getFieldType();
         if (!FieldTypeHelper::isRelation($fieldType)) {
             return $this->formatResult($entityConfig->get('label'), $this->doctrineTypeMapping[$fieldType]['type'], $this->doctrineTypeMapping[$fieldType]['options']);
         }
     }
     return false;
 }
 /**
  * Return view link options or simple text
  *
  * @param object          $targetEntity
  * @param ConfigInterface $field
  *
  * @throws \Doctrine\ORM\Mapping\MappingException
  * @return array|string
  */
 protected function getValueForManyToOne($targetEntity, ConfigInterface $field)
 {
     $targetFieldName = $field->get('target_field');
     $targetClassName = $field->get('target_entity');
     if (!class_exists($targetClassName)) {
         return '';
     }
     $title = (string) $this->propertyAccessor->getValue($targetEntity, $targetFieldName);
     $targetMetadata = $this->entityManager->getClassMetadata($targetClassName);
     $id = $this->propertyAccessor->getValue($targetEntity, $targetMetadata->getSingleIdentifierFieldName());
     $relationExtendConfig = $this->extendProvider->getConfig($targetClassName);
     $routeOptions = $relationExtendConfig->is('owner', ExtendScope::OWNER_CUSTOM) ? $this->getCustomEntityViewRouteOptions($targetClassName, $id) : $this->getClassViewRouteOptions($targetClassName, $id);
     if ($routeOptions['route']) {
         return ['link' => $this->router->generate($routeOptions['route'], $routeOptions['route_params']), 'title' => $title];
     }
     return $title;
 }
 /**
  * @param ConfigInterface $fieldConfig
  * @param string $relationKey
  */
 protected function createTargetRelation(ConfigInterface $fieldConfig, $relationKey)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $targetEntityClass = $fieldConfig->get('target_entity');
     $selfConfig = $this->extendConfigProvider->getConfig($selfFieldId->getClassName());
     $selfRelations = $selfConfig->get('relation');
     $selfRelationConfig =& $selfRelations[$relationKey];
     $selfRelationConfig['field_id'] = $selfFieldId;
     $targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass);
     $targetRelations = $targetConfig->get('relation');
     $targetRelationConfig =& $targetRelations[$relationKey];
     $targetRelationConfig['target_field_id'] = $selfFieldId;
     $selfConfig->set('relation', $selfRelations);
     $targetConfig->set('relation', $targetRelations);
     $this->extendConfigProvider->persist($targetConfig);
 }
Ejemplo n.º 23
0
 /**
  * @param ConfigInterface $config
  * @return bool
  */
 public function filterFields(ConfigInterface $config)
 {
     $extendConfig = $this->extendProvider->getConfigById($config->getId());
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $extendConfig->getId();
     // skip system, new and deleted fields
     if (!$config->is('owner', ExtendScope::OWNER_CUSTOM) || $config->is('state', ExtendScope::STATE_NEW) || $config->is('is_deleted')) {
         return false;
     }
     // skip invisible fields
     if (!$this->viewProvider->getConfigById($config->getId())->is('is_displayable')) {
         return false;
     }
     // skip relations if they are referenced to deleted entity
     $underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType());
     if (in_array($underlyingFieldType, RelationType::$anyToAnyRelations) && $this->extendProvider->getConfig($extendConfig->get('target_entity'))->is('is_deleted', true)) {
         return false;
     }
     return true;
 }
 public function testHandleUpdateNotAllowed()
 {
     $massActionMock = $this->getMock(MassActionInterface::class);
     $datagridMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface');
     $iteratorMock = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\IterableResultInterface');
     $entityName = 'Test\\EntityName';
     $hasConfig = true;
     $isEnabled = true;
     $isGranted = false;
     $data = [];
     $this->actionRepoMock->expects($this->once())->method('getEntityName')->with($datagridMock)->will($this->returnValue($entityName));
     $this->configMock->expects($this->once())->method('hasConfig')->with($entityName)->will($this->returnValue($hasConfig));
     $this->configMock->expects($this->once())->method('getConfig')->with($entityName)->will($this->returnValue(new Config(new EntityConfigId('extend', $entityName), ['update_mass_action_enabled' => $isEnabled])));
     $this->securityMock->expects($this->once())->method('isGranted')->with('EDIT', 'entity:' . $entityName)->will($this->returnValue($isGranted));
     $this->actionRepoMock->expects($this->never())->method('batchUpdate');
     $this->transMock->expects($this->once())->method('trans')->will($this->returnValue(uniqid()));
     $options = ActionConfiguration::create(['success_message' => '', 'error_message' => '']);
     $massActionMock->expects($this->any())->method('getOptions')->will($this->returnValue($options));
     $this->transMock->expects($this->once())->method('trans')->with('', ['%error%' => 'Action not configured or not allowed']);
     $this->loggerMock->expects($this->once())->method('debug');
     $actionResponse = $this->handler->handle(new MassActionHandlerArgs($massActionMock, $datagridMock, $iteratorMock, $data));
     $this->assertFalse($actionResponse->isSuccessful());
 }
 /**
  * Makes sure that both source and target entities know about a reverse relation
  *
  * @param ConfigInterface $fieldConfig
  */
 protected function ensureReverseRelationCompleted(ConfigInterface $fieldConfig)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $relationKey = $fieldConfig->get('relation_key');
     $selfConfig = $this->extendConfigProvider->getConfig($fieldConfigId->getClassName());
     $selfRelations = $selfConfig->get('relation', false, []);
     if (isset($selfRelations[$relationKey]['field_id']) && $selfRelations[$relationKey]['field_id']) {
         return;
     }
     $targetConfig = $this->extendConfigProvider->getConfig($fieldConfig->get('target_entity'));
     $targetRelations = $targetConfig->get('relation', false, []);
     if (!isset($targetRelations[$relationKey])) {
         return;
     }
     $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $selfRelations[$relationKey]['field_id'] = $selfFieldId;
     $targetRelations[$relationKey]['target_field_id'] = $selfFieldId;
     $selfConfig->set('relation', $selfRelations);
     $targetConfig->set('relation', $targetRelations);
     $this->extendConfigProvider->persist($selfConfig);
     $this->extendConfigProvider->persist($targetConfig);
 }
 public function testSetRolePrivileges()
 {
     $role = new AccountUserRole('TEST');
     $roleSecurityIdentity = new RoleSecurityIdentity($role);
     $firstClass = 'FirstClass';
     $secondClass = 'SecondClass';
     $unknownClass = 'UnknownClass';
     $request = new Request();
     $request->setMethod('GET');
     $firstEntityPrivilege = $this->createPrivilege('entity', 'entity:' . $firstClass, 'VIEW');
     $firstEntityConfig = $this->createClassConfigMock(true);
     $secondEntityPrivilege = $this->createPrivilege('entity', 'entity:' . $secondClass, 'VIEW');
     $secondEntityConfig = $this->createClassConfigMock(false);
     $unknownEntityPrivilege = $this->createPrivilege('entity', 'entity:' . $unknownClass, 'VIEW');
     $actionPrivilege = $this->createPrivilege('action', 'action', 'random_action');
     $entityForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $entityForm->expects($this->once())->method('setData')->willReturnCallback(function (ArrayCollection $actualPrivileges) use($firstEntityPrivilege) {
         $this->assertEquals([$firstEntityPrivilege], array_values($actualPrivileges->toArray()));
     });
     $actionForm = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $actionForm->expects($this->once())->method('setData')->willReturnCallback(function (ArrayCollection $actualPrivileges) use($actionPrivilege) {
         $this->assertEquals([$actionPrivilege], array_values($actualPrivileges->toArray()));
     });
     $form = $this->getMock('Symfony\\Component\\Form\\FormInterface');
     $form->expects($this->any())->method('get')->willReturnMap([['entity', $entityForm], ['action', $actionForm]]);
     $this->formFactory->expects($this->once())->method('create')->willReturn($form);
     $this->chainMetadataProvider->expects($this->once())->method('startProviderEmulation')->with(FrontendOwnershipMetadataProvider::ALIAS);
     $this->chainMetadataProvider->expects($this->once())->method('stopProviderEmulation');
     $this->aclManager->expects($this->any())->method('getSid')->with($role)->willReturn($roleSecurityIdentity);
     $this->privilegeRepository->expects($this->any())->method('getPrivileges')->with($roleSecurityIdentity)->willReturn(new ArrayCollection([$firstEntityPrivilege, $secondEntityPrivilege, $unknownEntityPrivilege, $actionPrivilege]));
     $this->ownershipConfigProvider->expects($this->any())->method('hasConfig')->willReturnMap([[$firstClass, null, true], [$secondClass, null, true], [$unknownClass, null, false]]);
     $this->ownershipConfigProvider->expects($this->any())->method('getConfig')->willReturnMap([[$firstClass, null, $firstEntityConfig], [$secondClass, null, $secondEntityConfig]]);
     $this->handler->setRequest($request);
     $this->handler->createForm($role);
     $this->handler->process($role);
 }
Ejemplo n.º 27
0
 /**
  * @param ConfigInterface         $extendConfig
  * @param ConfigProviderInterface $extendConfigProvider
  *
  * @return bool
  */
 protected function isApplicableField(ConfigInterface $extendConfig, ConfigProviderInterface $extendConfigProvider)
 {
     return !$extendConfig->is('is_deleted') && $extendConfig->is('owner', ExtendScope::OWNER_CUSTOM) && !$extendConfig->is('state', ExtendScope::STATE_NEW) && !in_array($extendConfig->getId()->getFieldType(), ['ref-one', 'ref-many']) && (!$extendConfig->has('target_entity') || !$extendConfigProvider->getConfig($extendConfig->get('target_entity'))->is('is_deleted'));
 }
Ejemplo n.º 28
0
 /**
  * @param string $className
  * @param string $fieldName
  *
  * @return bool
  */
 public function processRelationAsScalar($className, $fieldName)
 {
     /** @var Config $fieldConfig */
     $fieldConfig = $this->configProvider->getConfig($className, $fieldName);
     return $fieldConfig->is('process_as_scalar');
 }