Skip to content

Commit

Permalink
Merge pull request #65 from norzechowicz/update-dependencies
Browse files Browse the repository at this point in the history
Updated dependnecies
  • Loading branch information
Norbert Orzechowicz committed Jan 24, 2016
2 parents aa9e5f0 + 9c4ec65 commit 1646ccf
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 19 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ php:
- 5.5
- 5.6
- 7.0
- hhvm

sudo: false

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -41,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.2-dev"
"dev-master": "1.3-dev"
}
}
}
69 changes: 60 additions & 9 deletions lib/Extension/Symfony/ColumnTypeExtension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);

Expand Down Expand Up @@ -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';
Expand All @@ -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
);
Expand All @@ -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');
}
}
34 changes: 34 additions & 0 deletions lib/Extension/Symfony/ColumnTypeExtension/Symfony3RowType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace FSi\Component\DataGrid\Extension\Symfony\ColumnTypeExtension;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class Symfony3RowType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($options['fields'] as $field) {
$builder->add($field['name'], $field['type'], $field['options']);
}
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefault('fields', []);
}


/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'row';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
));

Expand Down Expand Up @@ -241,4 +241,9 @@ private function getDataMapperReturnCallback()
return $dataMapper;
});
}

private function isSymfony3()
{
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
}
}

0 comments on commit 1646ccf

Please sign in to comment.