Ejemplo n.º 1
0
 /**
  * @param FieldMetadata $fieldMetadata
  */
 protected function applyFieldMetadataConfig(FieldMetadata $fieldMetadata)
 {
     $this->entityConfigHelper->prepareFieldMetadataPropertyPath($fieldMetadata);
     $mergeConfig = $this->entityConfigHelper->getConfigByFieldMetadata(self::CONFIG_MERGE_SCOPE, $fieldMetadata);
     if ($mergeConfig) {
         $mergeOptions = $this->filterInverseOptions($mergeConfig->all(), $fieldMetadata->isDefinedBySourceEntity());
         $fieldMetadata->merge($mergeOptions);
     }
 }
Ejemplo n.º 2
0
 public function testPrepareFieldMetadataPropertyPathWithNotExtendField()
 {
     $className = 'Namespace\\Entity';
     $fieldName = 'test';
     $this->configManager->expects($this->once())->method('getProvider')->with('extend')->will($this->returnValue($this->extendConfigProvider));
     $fieldMetadata = $this->createFieldMetadata();
     $fieldMetadata->expects($this->once())->method('getSourceClassName')->will($this->returnValue($className));
     $fieldMetadata->expects($this->once())->method('getSourceFieldName')->will($this->returnValue($fieldName));
     $this->extendConfigProvider->expects($this->once())->method('hasConfig')->with($className, $fieldName)->will($this->returnValue(false));
     $fieldMetadata->expects($this->never())->method('set');
     $this->helper->prepareFieldMetadataPropertyPath($fieldMetadata);
 }
 public function testBuildFormExtendGuesser()
 {
     $entityName = User::class;
     $fieldName = 'orderPlacedAt';
     // pretend that it is extend field
     $expectedType = 'oro_datetime';
     $this->entityConfigMock->expects($this->once())->method('getConfig')->with('extend', $entityName, $fieldName)->willReturn(new Config(new FieldConfigId('extend', $entityName, $fieldName), ['is_extend' => true]));
     $this->extendTypeGuesser->expects($this->once())->method('guessType')->with($entityName, $fieldName)->willReturn(new TypeGuess($expectedType, [], Guess::HIGH_CONFIDENCE));
     $type = new GuessFieldType($this->entityConfigMock, $this->regularTypeGuesser);
     $form = $this->factory->create($type, null, ['data_class' => $entityName, 'field_name' => $fieldName]);
     $view = $form->createView();
     $this->assertCount(1, $view->children, 'Failed asserting that there is only one children');
     $fieldView = $view->offsetGet($fieldName);
     $this->assertEquals(sprintf('guess_field_type[%s]', $fieldName), $fieldView->vars['full_name'], 'Failed asserting that field name is correct');
     $this->assertEquals($expectedType, $form[$fieldName]->getConfig()->getType()->getName(), 'Failed asserting that correct underlying type was used');
 }
 /**
  * @param string $className
  * @param string $fieldName
  *
  * @return bool
  */
 protected function isExtendField($className, $fieldName)
 {
     $entityConfig = $this->entityConfigHelper->getConfig(EntityConfigHelper::EXTEND_CONFIG_SCOPE, $className, $fieldName);
     if ($entityConfig) {
         return $entityConfig->is('is_extend');
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * @param FieldMetadata $fieldMetadata
  * @return array
  */
 protected function initFieldMetadataDefaultLabel(FieldMetadata $fieldMetadata)
 {
     if ($fieldMetadata->has('label')) {
         return;
     }
     $labelCode = 'label';
     $className = $fieldMetadata->getSourceClassName();
     $fieldName = $fieldMetadata->getSourceFieldName();
     if (!$fieldMetadata->isDefinedBySourceEntity()) {
         $fieldName = null;
         if ($fieldMetadata->isCollection()) {
             $labelCode = 'plural_label';
         }
     }
     $entityConfig = $this->entityConfigHelper->getConfig(self::CONFIG_ENTITY_SCOPE, $className, $fieldName);
     if ($entityConfig) {
         $fieldMetadata->set('label', $entityConfig->get($labelCode));
     }
 }