diff --git a/.travis.yml b/.travis.yml index 352be8b..459794c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 5.5 - 5.6 - 7.0 - - hhvm sudo: false diff --git a/composer.json b/composer.json index 24e083d..4235744 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "doctrine/orm": "~2.5", "doctrine/common": "~2.5", "gedmo/doctrine-extensions": "~2.3.10", - "symfony/form" : "~2.4", - "symfony/doctrine-bridge": "~2.2", - "symfony/security-csrf" : "~2.4", - "symfony/routing" : "~2.2", - "symfony/http-foundation": "~2.2", - "symfony/dependency-injection" : "~2.2", + "symfony/form" : "^2.4|^3.0", + "symfony/doctrine-bridge": "^2.2|^3.0", + "symfony/security-csrf" : "^2.4|^3.0", + "symfony/routing" : "^2.2|^3.0", + "symfony/http-foundation": "^2.2|^3.0", + "symfony/dependency-injection" : "^2.2|^3.0", "phpunit/phpunit": "3.7.*" }, "autoload": { @@ -41,7 +41,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "1.3-dev" } } } diff --git a/lib/Extension/Symfony/ColumnTypeExtension/FormExtension.php b/lib/Extension/Symfony/ColumnTypeExtension/FormExtension.php index a99f034..9e876db 100644 --- a/lib/Extension/Symfony/ColumnTypeExtension/FormExtension.php +++ b/lib/Extension/Symfony/ColumnTypeExtension/FormExtension.php @@ -169,7 +169,7 @@ private function createForm(ColumnTypeInterface $column, $index, $data) case 'entity': $field = array( 'name' => $column->getOption('relation_field'), - 'type' => 'entity', + 'type' => $this->isSymfony3() ? $this->getEntityTypeName() : 'entity', 'options' => array(), ); @@ -214,7 +214,9 @@ private function createForm(ColumnTypeInterface $column, $index, $data) foreach ($fields as &$field) { $value = $column->getDataMapper()->getData($field['name'], $data); if (!isset($field['type'])) { - $field['type'] = 'datetime'; + $field['type'] = $this->isSymfony3() + ? $this->getDateTimeTypeName() + : 'datetime'; } if (is_numeric($value) && !isset($field['options']['input'])) { $field['options']['input'] = 'timestamp'; @@ -229,22 +231,34 @@ private function createForm(ColumnTypeInterface $column, $index, $data) break; } - $formBuilderOptions = array( - 'type' => new RowType($fields), - 'csrf_protection' => false, - - ); + if ($this->isSymfony3()) { + $formBuilderOptions = array( + 'entry_type' => $this->getRowTypeName(), + 'csrf_protection' => false, + ); + } else { + $formBuilderOptions = array( + 'type' => new RowType($fields), + 'csrf_protection' => false, + ); + } if (null !== $data) { - $formBuilderOptions['options'] = array( + $formBuilderOptions[$this->isSymfony3() ? 'entry_options' : 'options'] = array( 'data_class' => ClassUtils::getRealClass(get_class($data)) ); } + if ($this->isSymfony3()) { + $formBuilderOptions['entry_options']['fields'] = $fields; + } + //Create form builder. $formBuilder = $this->formFactory->createNamedBuilder( $this->formName, - 'collection', + ($this->isSymfony3()) + ? $this->getCollectionTypeName() + : 'collection', array($index => $data), $formBuilderOptions ); @@ -254,4 +268,41 @@ private function createForm(ColumnTypeInterface $column, $index, $data) return $this->forms[$formId]; } + + /** + * @return string + */ + private function getEntityTypeName() + { + return 'Symfony\Bridge\Doctrine\Form\Type\EntityType'; + } + + /** + * @return string + */ + private function getDateTimeTypeName() + { + return 'Symfony\Component\Form\Extension\Core\Type\DateTimeType'; + } + + private function getCollectionTypeName() + { + return 'Symfony\Component\Form\Extension\Core\Type\CollectionType'; + } + + /** + * @return string + */ + private function getRowTypeName() + { + return 'FSi\Component\DataGrid\Extension\Symfony\ColumnTypeExtension\Symfony3RowType'; + } + + /** + * @return bool + */ + private function isSymfony3() + { + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + } } diff --git a/lib/Extension/Symfony/ColumnTypeExtension/Symfony3RowType.php b/lib/Extension/Symfony/ColumnTypeExtension/Symfony3RowType.php new file mode 100644 index 0000000..7d68b83 --- /dev/null +++ b/lib/Extension/Symfony/ColumnTypeExtension/Symfony3RowType.php @@ -0,0 +1,34 @@ +add($field['name'], $field['type'], $field['options']); + } + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefault('fields', []); + } + + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'row'; + } +} \ No newline at end of file diff --git a/tests/Extension/Symfony/ColumnTypeExtension/FormExtensionTest.php b/tests/Extension/Symfony/ColumnTypeExtension/FormExtensionTest.php index adecda1..6fb392a 100644 --- a/tests/Extension/Symfony/ColumnTypeExtension/FormExtensionTest.php +++ b/tests/Extension/Symfony/ColumnTypeExtension/FormExtensionTest.php @@ -144,8 +144,8 @@ public function testSimpleBindData() 'editable' => true, 'form_options' => array(), 'form_type' => array( - 'name' => array('type' => 'text'), - 'author' => array('type' => 'text'), + 'name' => array('type' => $this->isSymfony3() ? 'Symfony\Component\Form\Extension\Core\Type\TextTyp' : 'text'), + 'author' => array('type' => $this->isSymfony3() ? 'Symfony\Component\Form\Extension\Core\Type\TextTyp' : 'text'), ) )); @@ -241,4 +241,9 @@ private function getDataMapperReturnCallback() return $dataMapper; }); } + + private function isSymfony3() + { + return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix'); + } }