public function testGetTreeOptions() { $inputData = [['id' => '3', 'name' => 'First BU', 'parent' => null, 'organization' => 1, 'children' => [['id' => '5', 'name' => 'Sub First BU', 'parent' => null, 'organization' => 1, 'children' => [['id' => '4', 'name' => 'Sub Sub First BU', 'parent' => null, 'organization' => 1]]]]], ['id' => '10', 'name' => 'Second BU', 'parent' => null, 'organization' => 1, 'children' => [['id' => 11, 'name' => 'Sub Second BU', 'parent' => null, 'organization' => 1]]], ['id' => '15', 'name' => 'BU wo children', 'parent' => null, 'organization' => 1]]; $result = $this->businessUnitManager->getTreeOptions($inputData); $expectedResult = ['3' => 'First BU', '5' => ' Sub First BU', '4' => ' Sub Sub First BU', '10' => 'Second BU', '11' => ' Sub Second BU', '15' => 'BU wo children']; $this->assertEquals($expectedResult, $result); }
/** * @param FormBuilderInterface $builder * @param User $user * @param string $className */ protected function addBusinessUnitOwnerField($builder, User $user, $className) { /** * Owner field is required for all entities except business unit */ if (!$this->checkIsBusinessUnitEntity($className)) { $validation = ['constraints' => [new NotBlank()], 'required' => true]; $emptyValueLabel = 'oro.business_unit.form.choose_business_user'; } else { $validation = ['required' => false]; $emptyValueLabel = 'oro.business_unit.form.none_business_user'; $this->fieldLabel = 'oro.organization.businessunit.parent.label'; } if ($this->isAssignGranted) { /** * If assign permission is granted, showing all available business units */ $builder->add($this->fieldName, 'oro_business_unit_tree_select', array_merge(['empty_value' => $emptyValueLabel, 'mapped' => true, 'label' => $this->fieldLabel, 'business_unit_ids' => $this->getBusinessUnitIds(), 'configs' => ['is_safe' => true], 'translatable_options' => false, 'choices' => $this->businessUnitManager->getTreeOptions($this->businessUnitManager->getBusinessUnitsTree(null, $this->getOrganizationContextId()))], $validation)); } else { $businessUnits = $user->getBusinessUnits(); if (count($businessUnits)) { $builder->add($this->fieldName, 'entity', array_merge(['class' => 'OroOrganizationBundle:BusinessUnit', 'property' => 'name', 'choices' => $businessUnits, 'mapped' => true, 'label' => $this->fieldLabel, 'translatable_options' => false], $validation)); } } }
/** * {@inheritdoc} */ public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('choices' => $this->businessUnitManager->getTreeOptions($this->businessUnitManager->getBusinessUnitsTree()))); }