/** * {@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 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; }
/** * @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 $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; }
/** * @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; }
/** * {@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; }
/** * 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; }
/** * @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; }
/** * 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; }
/** * {@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); }
/** * 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; }
/** * @param string $className * @param null|string $fieldName * @return bool */ public function hasConfig($className, $fieldName = null) { return $this->configProvider->hasConfig($className, $fieldName); }