/** * @param string $expected * @param Attribute $attribute * @dataProvider guessClassAttributeFormDataProvider */ public function testGuessClassAttributeForm($expected, Attribute $attribute) { $entityClass = 'TestEntity'; $fieldName = 'field'; $metadata = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $metadata->expects($this->any())->method('hasAssociation')->with($fieldName)->will($this->returnValue(true)); $metadata->expects($this->any())->method('getName')->will($this->returnValue($entityClass)); $this->setEntityMetadata(array($entityClass => $metadata)); $typeGuesser = $this->getMockForAbstractClass('Symfony\\Component\\Form\\FormTypeGuesserInterface'); $typeGuesser->expects($this->any())->method('guessType')->with($entityClass, $fieldName)->will($this->returnValue($expected)); $this->formRegistry->expects($this->any())->method('getTypeGuesser')->will($this->returnValue($typeGuesser)); $this->assertEquals($expected, $this->guesser->guessClassAttributeForm($entityClass, $attribute)); }
/** * @param array $options * @param string $rootClass * @param string $propertyPath * @return array */ protected function guessOptions(array $options, $rootClass, $propertyPath) { $guessedOptions = array('label', 'type', 'options'); $needGuess = false; foreach ($guessedOptions as $option) { if (empty($options[$option])) { $needGuess = true; break; } } if (!$needGuess) { return $options; } $attributeParameters = $this->attributeGuesser->guessAttributeParameters($rootClass, $propertyPath); if ($attributeParameters) { foreach ($guessedOptions as $option) { if (empty($options[$option]) && !empty($attributeParameters[$option])) { $options[$option] = $attributeParameters[$option]; } } } return $options; }
/** * @param Workflow $workflow * @param Attribute $attribute * @param array $attributeOptions * @return array */ protected function guessAttributeOptions(Workflow $workflow, Attribute $attribute, array $attributeOptions) { if (!empty($attributeOptions['form_type'])) { return $attributeOptions; } $relatedEntity = $workflow->getDefinition()->getRelatedEntity(); $typeGuess = $this->attributeGuesser->guessClassAttributeForm($relatedEntity, $attribute); if (!$typeGuess) { return $attributeOptions; } $attributeOptions['form_type'] = $typeGuess->getType(); $attributeOptions['options'] = array_merge_recursive($attributeOptions['options'], $typeGuess->getOptions()); return $attributeOptions; }