/** * @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])]); }
/** * {@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); } }
/** * @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); } } }
/** * 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); } }
/** * {@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); }
/** * 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); } } } } }
/** * 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'); }
/** * {@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); }
/** * 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)); }
/** * Returns entity * * @param string $entityName Entity name. Can be full class name or short form: Bundle:Entity. * @return array contains entity details: * . 'name' - entity full class name * . 'label' - entity label * . 'plural_label' - entity plural label * . 'icon' - an icon associated with an entity */ public function getEntity($entityName) { $className = $this->entityClassResolver->getEntityClass($entityName); $config = $this->entityConfigProvider->getConfig($className); $result = array(); $this->addEntity($result, $config->getId()->getClassName(), $config->get('label'), $config->get('plural_label'), $config->get('icon')); return reset($result); }
/** * 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 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)); }
/** * @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'); }
/** * 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']; }
/** * @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'); }
/** * @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); } } }
/** * {@inheritdoc} */ public function getValue(ResultRecordInterface $record) { $entity = $record->getValue('entity'); $entityClass = ClassUtils::getRealClass($entity); if ($this->mappingProvider->isClassSupported($entityClass)) { return parent::getValue($record); } else { $this->params[self::TEMPLATE_KEY] = $this->defaultTemplate; return $this->getTemplate()->render(['entityType' => $this->entityConfigProvider->getConfig($entityClass)->get('label'), 'entity' => $entity, 'indexer_item' => $record->getValue('indexer_item')]); } }
/** * {@inheritdoc} */ public function isIgnoredRelation(ClassMetadata $metadata, $associationName) { if ($metadata->isSingleValuedAssociation($associationName)) { $targetClassName = $metadata->getAssociationTargetClass($associationName); $groups = $this->groupingConfigProvider->getConfig($targetClassName)->get('groups'); if (!empty($groups) && in_array(GroupingScope::GROUP_DICTIONARY, $groups)) { return true; } } return false; }
/** * @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]]); }
/** * @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); }
/** * @param string $entityClass * @return string|null */ public function getContextGridByEntity($entityClass) { if (!empty($entityClass)) { $entityClass = $this->routingHelper->resolveEntityClass($entityClass); $config = $this->entityConfigProvider->getConfig($entityClass); $gridName = $config->get('context-grid'); if ($gridName) { return $gridName; } } return null; }
/** * @param FormInterface $field * @param FormView $view */ protected function updateTooltip(FormInterface $field, FormView $view) { $parentOptions = $field->getParent()->getConfig()->getOptions(); $parentClassName = isset($parentOptions['data_class']) ? $parentOptions['data_class'] : null; if (!isset($view->vars['tooltip']) && $parentClassName && $this->entityConfigProvider->hasConfig($parentClassName, $field->getName())) { $tooltip = $this->entityConfigProvider->getConfig($parentClassName, $field->getName())->get('description'); //@deprecated 1.9.0:1.11.0 tooltips.*.yml will be removed. Use Resources/translations/messages.*.yml instead if ($this->translator->hasTrans($tooltip, self::DEFAULT_TRANSLATE_DOMAIN) || $this->translator->hasTrans($tooltip, self::TOOLTIPS_TRANSLATE_DOMAIN)) { $view->vars['tooltip'] = $tooltip; } } }
/** * @param string $entityName * @param bool $isExtend * @param string $owner * @param string $mode */ public function createEntity($entityName, $isExtend = true, $owner = self::OWNER_CUSTOM, $mode = ConfigModelManager::MODE_DEFAULT) { $configManager = $this->configProvider->getConfigManager(); $configManager->createConfigEntityModel($entityName, $mode); $extendConfig = $this->configProvider->getConfig($entityName); $extendConfig->set('owner', $owner); $extendConfig->set('state', self::STATE_NEW); $extendConfig->set('is_extend', $isExtend); $configManager->persist($extendConfig); $entityFieldConfig = $configManager->getProvider('entity')->getConfig($entityName, 'id'); $entityFieldConfig->set('label', 'Id'); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener(FormEvents::POST_SUBMIT, function () use($options) { /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $options['config_id']; $entityConfig = $this->extendConfigProvider->getConfig($fieldConfigId->getClassName()); if ($entityConfig->is('state', ExtendScope::STATE_ACTIVE) && !$this->hasRelation($entityConfig, $this->getRelationKey($fieldConfigId))) { $entityConfig->set('state', ExtendScope::STATE_UPDATE); $this->extendConfigProvider->persist($entityConfig); $this->extendConfigProvider->flush(); } }); }
public function testConfig() { $this->assertEquals($this->configManager, $this->configProvider->getConfigManager()); $this->assertEquals(true, $this->configProvider->hasConfig(DemoEntity::ENTITY_NAME)); $this->assertEquals($this->entityConfig, $this->configProvider->getConfig(DemoEntity::ENTITY_NAME)); $this->assertEquals('testScope', $this->configProvider->getScope()); $entityConfigId = new EntityConfigId('testScope', DemoEntity::ENTITY_NAME); $fieldConfigId = new FieldConfigId('testScope', DemoEntity::ENTITY_NAME, 'testField', 'string'); $this->assertEquals($entityConfigId, $this->configProvider->getId(DemoEntity::ENTITY_NAME)); $this->assertEquals($fieldConfigId, $this->configProvider->getId(DemoEntity::ENTITY_NAME, 'testField', 'string')); $entityConfigIdWithOtherScope = new EntityConfigId('otherScope', DemoEntity::ENTITY_NAME); $this->assertEquals($this->entityConfig, $this->configProvider->getConfigById($entityConfigIdWithOtherScope)); }
/** * {@inheritdoc} */ public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig) { $className = $extendConfig->getId()->getClassName(); $indices = $extendConfig->get('index'); // TODO: need to be changed to fieldName => columnName // TODO: should be done in scope https://magecore.atlassian.net/browse/BAP-3940 foreach ($indices as $columnName => $enabled) { $fieldConfig = $this->extendConfigProvider->getConfig($className, $columnName); if ($enabled && !$fieldConfig->is('state', ExtendScope::STATE_NEW)) { $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName); $metadataBuilder->addIndex([$columnName], $indexName); } } }
/** * @param mixed $entity * @param string $entityClass * @param bool $show * @return bool */ public function isEntityAuditable($entity, $entityClass, $show) { if (!is_object($entity) || $show) { return $show; } $classEmpty = empty($entityClass); if ($classEmpty && $entity instanceof EntityConfigModel) { $className = $entity->getClassName(); } elseif ($classEmpty) { $className = ClassUtils::getClass($entity); } else { $className = str_replace('_', '\\', $entityClass); } return $this->configProvider->hasConfig($className) && $this->configProvider->getConfig($className)->is('auditable'); }
/** * {@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 EmailBodyAdded $event */ public function linkToScope(EmailBodyAdded $event) { if ($this->securityFacade->getToken() !== null && !$this->securityFacade->isGranted('CREATE', 'entity:' . AttachmentScope::ATTACHMENT)) { return; } $email = $event->getEmail(); $entities = $this->activityListProvider->getTargetEntities($email); foreach ($entities as $entity) { if ((bool) $this->configProvider->getConfig(ClassUtils::getClass($entity))->get('auto_link_attachments')) { foreach ($email->getEmailBody()->getAttachments() as $attachment) { $this->attachmentManager->linkEmailAttachmentToTargetEntity($attachment, $entity); } } } }